diff --git a/lib/Config/Populator.php b/lib/Config/Populator.php index ac7819ece5..28c55cd6c3 100644 --- a/lib/Config/Populator.php +++ b/lib/Config/Populator.php @@ -31,6 +31,7 @@ use MailPoet\Subscribers\NewSubscriberNotificationMailer; use MailPoet\Subscribers\Source; use MailPoet\Subscription\Captcha; use MailPoet\Util\Helpers; +use MailPoet\WooCommerce\TransactionalEmails; use MailPoet\WP\Functions as WPFunctions; class Populator { @@ -50,12 +51,16 @@ class Populator { /** @var FeaturesController */ private $flags_controller; + /** @var TransactionalEmails */ + private $wc_transactional_emails; + function __construct( SettingsController $settings, WPFunctions $wp, Captcha $captcha, ReferralDetector $referralDetector, - FeaturesController $flags_controller + FeaturesController $flags_controller, + TransactionalEmails $wc_transactional_emails ) { $this->settings = $settings; $this->wp = $wp; @@ -143,6 +148,7 @@ class Populator { 'FarmersMarket', ]; $this->flags_controller = $flags_controller; + $this->wc_transactional_emails = $wc_transactional_emails; } function up() { @@ -169,6 +175,7 @@ class Populator { $this->scheduleSubscriberLinkTokens(); $this->detectReferral(); $this->updateFormsSuccessMessages(); + $this->initWooCommerceTransactionalEmails(); } private function createMailPoetPage() { @@ -674,4 +681,11 @@ class Populator { private function detectReferral() { $this->referralDetector->detect(); } + + private function initWooCommerceTransactionalEmails() { + $feature_enabled = $this->flags_controller->isSupported(FeaturesController::WC_TRANSACTIONAL_EMAILS_CUSTOMIZER); + if ($feature_enabled) { + $this->wc_transactional_emails->init(); + } + } } diff --git a/lib/DI/ContainerConfigurator.php b/lib/DI/ContainerConfigurator.php index d5b701d70e..3e7789166e 100644 --- a/lib/DI/ContainerConfigurator.php +++ b/lib/DI/ContainerConfigurator.php @@ -193,6 +193,7 @@ class ContainerConfigurator implements IContainerConfigurator { // WooCommerce $container->autowire(\MailPoet\WooCommerce\Helper::class)->setPublic(true); $container->autowire(\MailPoet\WooCommerce\Subscription::class)->setPublic(true); + $container->autowire(\MailPoet\WooCommerce\TransactionalEmails::class); // WordPress $container->autowire(\MailPoet\WP\Functions::class)->setPublic(true); return $container; diff --git a/lib/WooCommerce/TransactionalEmails.php b/lib/WooCommerce/TransactionalEmails.php new file mode 100644 index 0000000000..239120dbdf --- /dev/null +++ b/lib/WooCommerce/TransactionalEmails.php @@ -0,0 +1,833 @@ +wp = $wp; + $this->settings = $settings; + } + + function init() { + $saved_email_id = (bool)$this->settings->get(self::SETTING_EMAIL_ID, false); + if (!$saved_email_id) { + $email = Newsletter::createOrUpdate([ + 'type' => Newsletter::TYPE_WC_TRANSACTIONAL_EMAIL, + 'subject' => 'WooCommerce Transactional Email', + 'preheader' => '', + 'body' => json_encode($this->getBody()), + ]); + $this->settings->set(self::SETTING_EMAIL_ID, $email->id); + } + } + + private function getBody() { + $social_icon_url = Env::$assets_url . '/img/newsletter_editor/social-icons'; + $wc_header_image = $this->wp->getOption('woocommerce_email_header_image', ''); + return [ + 'content' => + [ + 'type' => 'container', + 'columnLayout' => false, + 'orientation' => 'vertical', + 'image' => + [ + 'src' => null, + 'display' => 'scale', + ], + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + ], + ], + 'blocks' => + [ + 0 => + [ + 'type' => 'container', + 'columnLayout' => false, + 'orientation' => 'horizontal', + 'image' => + [ + 'src' => null, + 'display' => 'scale', + ], + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => '#eeeeee', + ], + ], + 'blocks' => + [ + 0 => + [ + 'type' => 'container', + 'columnLayout' => false, + 'orientation' => 'vertical', + 'image' => + [ + 'src' => null, + 'display' => 'scale', + ], + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + ], + ], + 'blocks' => + [ + 0 => + [ + 'type' => 'spacer', + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + 'height' => '20px', + ], + ], + ], + 1 => + [ + 'type' => 'image', + 'link' => '', + 'src' => $wc_header_image, + 'alt' => 'mailpoet-logo', + 'fullWidth' => false, + 'width' => '160px', + 'height' => '490px', + 'styles' => + [ + 'block' => + [ + 'textAlign' => 'center', + ], + ], + ], + 2 => + [ + 'type' => 'spacer', + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + 'height' => '20px', + ], + ], + ], + ], + ], + ], + ], + 1 => + [ + 'type' => 'container', + 'columnLayout' => false, + 'orientation' => 'horizontal', + 'image' => + [ + 'src' => null, + 'display' => 'scale', + ], + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + ], + ], + 'blocks' => + [ + 0 => + [ + 'type' => 'container', + 'columnLayout' => false, + 'orientation' => 'vertical', + 'image' => + [ + 'src' => null, + 'display' => 'scale', + ], + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + ], + ], + 'blocks' => + [ + 0 => + [ + 'type' => 'text', + 'text' => '
WIDGET "WC HEADING" GOES HERE
+(instead of the column)
', + ], + ], + ], + ], + ], + 2 => + [ + 'type' => 'container', + 'columnLayout' => false, + 'orientation' => 'horizontal', + 'image' => + [ + 'src' => null, + 'display' => 'scale', + ], + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + ], + ], + 'blocks' => + [ + 0 => + [ + 'type' => 'container', + 'columnLayout' => false, + 'orientation' => 'vertical', + 'image' => + [ + 'src' => null, + 'display' => 'scale', + ], + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + ], + ], + 'blocks' => + [ + 0 => + [ + 'type' => 'spacer', + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + 'height' => '20px', + ], + ], + ], + ], + ], + ], + ], + 3 => + [ + 'type' => 'container', + 'columnLayout' => false, + 'orientation' => 'horizontal', + 'image' => + [ + 'src' => null, + 'display' => 'scale', + ], + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + ], + ], + 'blocks' => + [ + 0 => + [ + 'type' => 'container', + 'columnLayout' => false, + 'orientation' => 'vertical', + 'image' => + [ + 'src' => null, + 'display' => 'scale', + ], + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + ], + ], + 'blocks' => + [ + 0 => + [ + 'type' => 'text', + 'text' => 'WIDGET "WC CONTENT" GOES HERE
+(instead of the column)
', + ], + ], + ], + ], + ], + 4 => + [ + 'type' => 'container', + 'columnLayout' => false, + 'orientation' => 'horizontal', + 'image' => + [ + 'src' => null, + 'display' => 'scale', + ], + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => '#ffffff', + ], + ], + 'blocks' => + [ + 0 => + [ + 'type' => 'container', + 'columnLayout' => false, + 'orientation' => 'vertical', + 'image' => + [ + 'src' => null, + 'display' => 'scale', + ], + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + ], + ], + 'blocks' => + [ + 0 => + [ + 'type' => 'spacer', + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + 'height' => '20px', + ], + ], + ], + ], + ], + ], + ], + 5 => + [ + 'type' => 'container', + 'columnLayout' => false, + 'orientation' => 'horizontal', + 'image' => + [ + 'src' => null, + 'display' => 'scale', + ], + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => '#eeeeee', + ], + ], + 'blocks' => + [ + 0 => + [ + 'type' => 'container', + 'columnLayout' => false, + 'orientation' => 'vertical', + 'image' => + [ + 'src' => null, + 'display' => 'scale', + ], + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + ], + ], + 'blocks' => + [ + 0 => + [ + 'type' => 'spacer', + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + 'height' => '20px', + ], + ], + ], + 1 => + [ + 'type' => 'text', + 'text' => 'Footer text
', + ], + ], + ], + ], + ], + ], + ], + 'globalStyles' => + [ + 'text' => + [ + 'fontColor' => '#111111', + 'fontFamily' => 'Arial', + 'fontSize' => '16px', + 'lineHeight' => '1.6', + ], + 'h1' => + [ + 'fontColor' => '#333333', + 'fontFamily' => 'Source Sans Pro', + 'fontSize' => '36px', + 'lineHeight' => '1.6', + ], + 'h2' => + [ + 'fontColor' => '#222222', + 'fontFamily' => 'Verdana', + 'fontSize' => '24px', + 'lineHeight' => '1.6', + ], + 'h3' => + [ + 'fontColor' => '#333333', + 'fontFamily' => 'Trebuchet MS', + 'fontSize' => '22px', + 'lineHeight' => '1.6', + ], + 'link' => + [ + 'fontColor' => '#21759B', + 'textDecoration' => 'underline', + ], + 'wrapper' => + [ + 'backgroundColor' => '#ffffff', + ], + 'body' => + [ + 'backgroundColor' => '#eeeeee', + ], + ], + 'blockDefaults' => + [ + 'automatedLatestContent' => + [ + 'amount' => '5', + 'withLayout' => false, + 'contentType' => 'post', + 'inclusionType' => 'include', + 'displayType' => 'excerpt', + 'titleFormat' => 'h1', + 'titleAlignment' => 'left', + 'titleIsLink' => false, + 'imageFullWidth' => false, + 'featuredImagePosition' => 'belowTitle', + 'showAuthor' => 'no', + 'authorPrecededBy' => 'Author:', + 'showCategories' => 'no', + 'categoriesPrecededBy' => 'Categories:', + 'readMoreType' => 'button', + 'readMoreText' => 'Read more', + 'readMoreButton' => + [ + 'text' => 'Read more', + 'url' => '[postLink]', + 'context' => 'automatedLatestContent.readMoreButton', + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => '#2ea1cd', + 'borderColor' => '#0074a2', + 'borderWidth' => '1px', + 'borderRadius' => '5px', + 'borderStyle' => 'solid', + 'width' => '180px', + 'lineHeight' => '40px', + 'fontColor' => '#ffffff', + 'fontFamily' => 'Verdana', + 'fontSize' => '18px', + 'fontWeight' => 'normal', + 'textAlign' => 'center', + ], + ], + ], + 'sortBy' => 'newest', + 'showDivider' => true, + 'divider' => + [ + 'context' => 'automatedLatestContent.divider', + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + 'padding' => '13px', + 'borderStyle' => 'solid', + 'borderWidth' => '3px', + 'borderColor' => '#aaaaaa', + ], + ], + ], + 'backgroundColor' => '#ffffff', + 'backgroundColorAlternate' => '#eeeeee', + ], + 'automatedLatestContentLayout' => + [ + 'amount' => '5', + 'withLayout' => true, + 'contentType' => 'post', + 'inclusionType' => 'include', + 'displayType' => 'excerpt', + 'titleFormat' => 'h1', + 'titleAlignment' => 'left', + 'titleIsLink' => false, + 'imageFullWidth' => false, + 'featuredImagePosition' => 'alternate', + 'showAuthor' => 'no', + 'authorPrecededBy' => 'Author:', + 'showCategories' => 'no', + 'categoriesPrecededBy' => 'Categories:', + 'readMoreType' => 'button', + 'readMoreText' => 'Read more', + 'readMoreButton' => + [ + 'text' => 'Read more', + 'url' => '[postLink]', + 'context' => 'automatedLatestContentLayout.readMoreButton', + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => '#2ea1cd', + 'borderColor' => '#0074a2', + 'borderWidth' => '1px', + 'borderRadius' => '5px', + 'borderStyle' => 'solid', + 'width' => '180px', + 'lineHeight' => '40px', + 'fontColor' => '#ffffff', + 'fontFamily' => 'Verdana', + 'fontSize' => '18px', + 'fontWeight' => 'normal', + 'textAlign' => 'center', + ], + ], + ], + 'sortBy' => 'newest', + 'showDivider' => true, + 'divider' => + [ + 'context' => 'automatedLatestContentLayout.divider', + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + 'padding' => '13px', + 'borderStyle' => 'solid', + 'borderWidth' => '3px', + 'borderColor' => '#aaaaaa', + ], + ], + ], + 'backgroundColor' => '#ffffff', + 'backgroundColorAlternate' => '#eeeeee', + ], + 'button' => + [ + 'text' => 'Button', + 'url' => '', + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => '#2ea1cd', + 'borderColor' => '#0074a2', + 'borderWidth' => '1px', + 'borderRadius' => '5px', + 'borderStyle' => 'solid', + 'width' => '180px', + 'lineHeight' => '40px', + 'fontColor' => '#ffffff', + 'fontFamily' => 'Verdana', + 'fontSize' => '18px', + 'fontWeight' => 'normal', + 'textAlign' => 'center', + ], + ], + ], + 'divider' => + [ + 'styles' => + [ + 'block' => + [ + 'backgroundColor' => 'transparent', + 'padding' => '13px', + 'borderStyle' => 'solid', + 'borderWidth' => '3px', + 'borderColor' => '#aaaaaa', + ], + ], + ], + 'footer' => + [ + 'text' => 'Unsubscribe | Manage subscription
Add your postal address here!