Sync WC customizer styles to WooCommerce settings [MAILPOET-2569]
This commit is contained in:
@ -357,10 +357,13 @@ class Initializer {
|
||||
$feature_enabled = $this->flags_controller->isSupported(FeaturesController::WC_TRANSACTIONAL_EMAILS_CUSTOMIZER);
|
||||
$opt_in_enabled = $this->settings->get('woocommerce.use_mailpoet_editor', false);
|
||||
$wc_enabled = $this->wc_helper->isWooCommerceActive();
|
||||
if ($feature_enabled && $wc_enabled && $opt_in_enabled) {
|
||||
if ($feature_enabled && $wc_enabled) {
|
||||
$this->wc_transactional_emails->enableEmailSettingsSyncToWooCommerce();
|
||||
if ($opt_in_enabled) {
|
||||
$this->wc_transactional_emails->useTemplateForWoocommerceEmails();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function includeAutomaticEmailsData() {
|
||||
$data = [
|
||||
|
@ -129,7 +129,28 @@ class TransactionalEmails {
|
||||
);
|
||||
}
|
||||
|
||||
private function getWCEmailSettings() {
|
||||
public function enableEmailSettingsSyncToWooCommerce() {
|
||||
$this->wp->addAction('mailpoet_api_newsletters_save_after', [$this, 'syncEmailSettingsToWooCommerce']);
|
||||
}
|
||||
|
||||
public function syncEmailSettingsToWooCommerce(Newsletter $newsletter) {
|
||||
if ($newsletter->type !== NewsletterEntity::TYPE_WC_TRANSACTIONAL_EMAIL) {
|
||||
return false;
|
||||
}
|
||||
$newsletter_array = $newsletter->asArray();
|
||||
$styles = $newsletter_array['body']['globalStyles'];
|
||||
$options_to_sync = [
|
||||
'woocommerce_email_background_color' => $styles['body']['backgroundColor'],
|
||||
'woocommerce_email_base_color' => $styles['woocommerce']['brandingColor'],
|
||||
'woocommerce_email_body_background_color' => $styles['wrapper']['backgroundColor'],
|
||||
'woocommerce_email_text_color' => $styles['text']['fontColor'],
|
||||
];
|
||||
foreach ($options_to_sync as $wc_name => $value) {
|
||||
$this->wp->updateOption($wc_name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function getWCEmailSettings() {
|
||||
$wc_email_settings = [
|
||||
'woocommerce_email_background_color' => '#f7f7f7',
|
||||
'woocommerce_email_base_color' => '#333333',
|
||||
|
@ -84,6 +84,92 @@ class TransactionalEmailsTest extends \MailPoetTest {
|
||||
expect(json_encode($email->getBody()))->contains('my-awesome-image-url');
|
||||
}
|
||||
|
||||
function testItSynchronizesEmailSettingsToWooCommerce() {
|
||||
$newsletter = new NewsletterEntity;
|
||||
$newsletter->setType(Newsletter::TYPE_WC_TRANSACTIONAL_EMAIL);
|
||||
$newsletter->setSubject('WooCommerce Transactional Email');
|
||||
$newsletter->setBody([
|
||||
'globalStyles' => [
|
||||
'text' =>
|
||||
[
|
||||
'fontColor' => '#111111',
|
||||
'fontFamily' => 'Arial',
|
||||
'fontSize' => '14px',
|
||||
'lineHeight' => '1.6',
|
||||
],
|
||||
'h1' =>
|
||||
[
|
||||
'fontColor' => '#222222',
|
||||
'fontFamily' => 'Source Sans Pro',
|
||||
'fontSize' => '36px',
|
||||
'lineHeight' => '1.6',
|
||||
],
|
||||
'h2' =>
|
||||
[
|
||||
'fontColor' => '#333333',
|
||||
'fontFamily' => 'Verdana',
|
||||
'fontSize' => '24px',
|
||||
'lineHeight' => '1.6',
|
||||
],
|
||||
'h3' =>
|
||||
[
|
||||
'fontColor' => '#444444',
|
||||
'fontFamily' => 'Trebuchet MS',
|
||||
'fontSize' => '22px',
|
||||
'lineHeight' => '1.6',
|
||||
],
|
||||
'link' =>
|
||||
[
|
||||
'fontColor' => '#555555',
|
||||
'textDecoration' => 'underline',
|
||||
],
|
||||
'wrapper' =>
|
||||
[
|
||||
'backgroundColor' => '#666666',
|
||||
],
|
||||
'body' =>
|
||||
[
|
||||
'backgroundColor' => '#777777',
|
||||
],
|
||||
'woocommerce' =>
|
||||
[
|
||||
'brandingColor' => '#888888',
|
||||
'headingFontColor' => '#999999',
|
||||
],
|
||||
],
|
||||
]);
|
||||
$this->newsletters_repository->persist($newsletter);
|
||||
$this->newsletters_repository->flush();
|
||||
|
||||
$options = [];
|
||||
$wp = Stub::make(new WPFunctions, [
|
||||
'updateOption' => function($name, $value) use (&$options) {
|
||||
$options[$name] = $value;
|
||||
},
|
||||
'getOption' => function($name) use (&$options) {
|
||||
return $options[$name];
|
||||
},
|
||||
]);
|
||||
|
||||
$transactional_emails = new TransactionalEmails(
|
||||
$wp,
|
||||
$this->settings,
|
||||
ContainerWrapper::getInstance()->get(Template::class),
|
||||
ContainerWrapper::getInstance()->get(Renderer::class),
|
||||
Stub::makeEmpty(WooCommerceHelper::class),
|
||||
$this->newsletters_repository
|
||||
);
|
||||
$transactional_emails->enableEmailSettingsSyncToWooCommerce();
|
||||
|
||||
$newsletter = Newsletter::findOne($newsletter->getId());
|
||||
$wp->doAction('mailpoet_api_newsletters_save_after', $newsletter);
|
||||
|
||||
expect($wp->getOption('woocommerce_email_background_color'))->equals('#777777');
|
||||
expect($wp->getOption('woocommerce_email_base_color'))->equals('#888888');
|
||||
expect($wp->getOption('woocommerce_email_body_background_color'))->equals('#666666');
|
||||
expect($wp->getOption('woocommerce_email_text_color'))->equals('#111111');
|
||||
}
|
||||
|
||||
function testUseTemplateForWCEmails() {
|
||||
$added_actions = [];
|
||||
$removed_actions = [];
|
||||
|
Reference in New Issue
Block a user