'; const WC_HEADING_AFTER = ' '; /** @var AbandonedCartContent */ private $abandonedCartContent; /** @var AutomatedLatestContentBlock */ private $automatedLatestContent; /** @var ContentPreprocessor */ private $wooCommerceContentPreprocessor; /*** @var CouponPreProcessor */ private $couponPreProcessor; public function __construct( AbandonedCartContent $abandonedCartContent, AutomatedLatestContentBlock $automatedLatestContent, ContentPreprocessor $wooCommerceContentPreprocessor, CouponPreProcessor $couponPreProcessor ) { $this->abandonedCartContent = $abandonedCartContent; $this->automatedLatestContent = $automatedLatestContent; $this->wooCommerceContentPreprocessor = $wooCommerceContentPreprocessor; $this->couponPreProcessor = $couponPreProcessor; } /** * @param array $content * @param NewsletterEntity $newsletter * @return array */ public function process(NewsletterEntity $newsletter, $content, bool $preview = false, SendingQueueEntity $sendingQueue = null) { if (!array_key_exists('blocks', $content)) { return $content; } $blocks = []; $contentBlocks = $content['blocks']; $contentBlocks = $this->couponPreProcessor->processCoupons($newsletter, $contentBlocks, $preview); foreach ($contentBlocks as $block) { $processedBlock = $this->processBlock($newsletter, $block, $preview, $sendingQueue); if (!empty($processedBlock)) { $blocks = array_merge($blocks, $processedBlock); } } $content['blocks'] = $blocks; return $content; } public function processBlock(NewsletterEntity $newsletter, array $block, bool $preview = false, SendingQueueEntity $sendingQueue = null): array { switch ($block['type']) { case 'abandonedCartContent': return $this->abandonedCartContent->render($newsletter, $block, $preview, $sendingQueue); case 'automatedLatestContentLayout': return $this->automatedLatestContent->render($newsletter, $block); case 'woocommerceHeading': return $this->wooCommerceContentPreprocessor->preprocessHeader(); case 'woocommerceContent': return $this->wooCommerceContentPreprocessor->preprocessContent(); } return [$block]; } }