Create WC content preprocessor

[MAILPOET-3638]
This commit is contained in:
Jan Lysý
2021-06-04 14:45:58 +02:00
committed by Veljko V
parent c1ffc12e1a
commit f3586dfe2e
4 changed files with 71 additions and 38 deletions

View File

@@ -3,16 +3,12 @@
namespace MailPoet\Newsletter\Renderer;
use MailPoet\Entities\NewsletterEntity;
use MailPoet\Newsletter\Editor\LayoutHelper;
use MailPoet\Newsletter\Renderer\Blocks\AbandonedCartContent;
use MailPoet\Newsletter\Renderer\Blocks\AutomatedLatestContentBlock;
use MailPoet\Tasks\Sending as SendingTask;
use MailPoet\WooCommerce\TransactionalEmails;
use MailPoet\WooCommerce\TransactionalEmails\ContentPreprocessor;
class Preprocessor {
const WC_HEADING_PLACEHOLDER = '[mailpoet_woocommerce_heading_placeholder]';
const WC_CONTENT_PLACEHOLDER = '[mailpoet_woocommerce_content_placeholder]';
const WC_HEADING_BEFORE = '
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-spacing:0;mso-table-lspace:0;mso-table-rspace:0">
<tr>
@@ -28,17 +24,17 @@ class Preprocessor {
/** @var AutomatedLatestContentBlock */
private $automatedLatestContent;
/** @var TransactionalEmails */
private $transactionalEmails;
/** @var ContentPreprocessor */
private $wooCommerceContentPreprocessor;
public function __construct(
AbandonedCartContent $abandonedCartContent,
AutomatedLatestContentBlock $automatedLatestContent,
TransactionalEmails $transactionalEmails
ContentPreprocessor $wooCommerceContentPreprocessor
) {
$this->abandonedCartContent = $abandonedCartContent;
$this->automatedLatestContent = $automatedLatestContent;
$this->transactionalEmails = $transactionalEmails;
$this->wooCommerceContentPreprocessor = $wooCommerceContentPreprocessor;
}
/**
@@ -68,34 +64,10 @@ class Preprocessor {
case 'automatedLatestContentLayout':
return $this->automatedLatestContent->render($newsletter, $block);
case 'woocommerceHeading':
$wcEmailSettings = $this->transactionalEmails->getWCEmailSettings();
$content = self::WC_HEADING_BEFORE . '<h1 style="color:' . $wcEmailSettings['base_text_color'] . ';">' . self::WC_HEADING_PLACEHOLDER . '</h1>' . self::WC_HEADING_AFTER;
return $this->renderTextBlock($content, ['backgroundColor' => $wcEmailSettings['base_color']]);
return $this->wooCommerceContentPreprocessor->preprocessHeader();
case 'woocommerceContent':
return $this->renderPlaceholderBlock(self::WC_CONTENT_PLACEHOLDER);
return $this->wooCommerceContentPreprocessor->preprocessContent();
}
return [$block];
}
private function renderTextBlock(string $text, array $styles = []): array {
return [
LayoutHelper::row([
LayoutHelper::col([[
'type' => 'text',
'text' => $text,
]]),
], $styles),
];
}
private function renderPlaceholderBlock(string $placeholder): array {
return [
LayoutHelper::row([
LayoutHelper::col([[
'type' => 'placeholder',
'placeholder' => $placeholder,
]]),
]),
];
}
}