Add heading content

[MAILPOET-2278]
This commit is contained in:
Amine Ben hammou
2019-10-17 10:46:56 +01:00
committed by Jack Kitterhing
parent 6697424030
commit ad899e436c
7 changed files with 49 additions and 6 deletions

View File

@ -5,10 +5,11 @@ import App from 'newsletter_editor/App';
import BaseBlock from 'newsletter_editor/blocks/base'; import BaseBlock from 'newsletter_editor/blocks/base';
const BlockModel = BaseBlock.BlockModel.extend({ const BlockModel = BaseBlock.BlockModel.extend({
stale: ['styles.backgroundColor'], stale: ['styles.backgroundColor', 'content'],
defaults() { defaults() {
return this._getDefaults({ return this._getDefaults({
type: 'woocommerceHeading', type: 'woocommerceHeading',
content: '',
styles: { styles: {
fontColor: '#000000', fontColor: '#000000',
backgroundColor: '#FFFFFF', backgroundColor: '#FFFFFF',
@ -71,7 +72,7 @@ const WidgetView = BaseBlock.WidgetView.extend({
}); });
const BlockView = BaseBlock.BlockView.extend({ const BlockView = BaseBlock.BlockView.extend({
className: 'mailpoet_block mailpoet_woocommerce_heading_block mailpoet_droppable_block', className: 'mailpoet_container mailpoet_woocommerce_heading_block mailpoet_droppable_block',
initialize: function initialize() { initialize: function initialize() {
BaseBlock.BlockView.prototype.initialize.apply(this, arguments); BaseBlock.BlockView.prototype.initialize.apply(this, arguments);
this.listenTo(this.model, 'change:styles.fontColor', this.render); this.listenTo(this.model, 'change:styles.fontColor', this.render);
@ -94,6 +95,7 @@ const BlockView = BaseBlock.BlockView.extend({
return { return {
viewCid: this.cid, viewCid: this.cid,
model: this.model.toJSON(), model: this.model.toJSON(),
content: this.model.get('content'),
styles: this.model.get('styles').toJSON(), styles: this.model.get('styles').toJSON(),
}; };
}, },

View File

@ -20,7 +20,7 @@ Module.save = function () {
// Stringify to enable transmission of primitive non-string value types // Stringify to enable transmission of primitive non-string value types
if (!_.isUndefined(json.body)) { if (!_.isUndefined(json.body)) {
delete json.body.blockDefaults.woocommerceHeading.styles.backgroundColor; delete json.body.blockDefaults.woocommerceHeading;
delete json.body.blockDefaults.woocommerceContent; delete json.body.blockDefaults.woocommerceContent;
json.body = JSON.stringify(json.body); json.body = JSON.stringify(json.body);
} }

View File

@ -10,6 +10,7 @@ use MailPoet\Services\Bridge;
use MailPoet\Settings\SettingsController; use MailPoet\Settings\SettingsController;
use MailPoet\Settings\UserFlagsController; use MailPoet\Settings\UserFlagsController;
use MailPoet\WooCommerce\Helper as WooCommerceHelper; use MailPoet\WooCommerce\Helper as WooCommerceHelper;
use MailPoet\WooCommerce\TransactionalEmails;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
class NewsletterEditor { class NewsletterEditor {
@ -28,18 +29,23 @@ class NewsletterEditor {
/** @var WPFunctions */ /** @var WPFunctions */
private $wp; private $wp;
/** @var TransactionalEmails */
private $wc_transactional_emails;
function __construct( function __construct(
PageRenderer $page_renderer, PageRenderer $page_renderer,
SettingsController $settings, SettingsController $settings,
UserFlagsController $user_flags, UserFlagsController $user_flags,
WooCommerceHelper $woocommerce_helper, WooCommerceHelper $woocommerce_helper,
WPFunctions $wp WPFunctions $wp,
TransactionalEmails $wc_transactional_emails
) { ) {
$this->page_renderer = $page_renderer; $this->page_renderer = $page_renderer;
$this->settings = $settings; $this->settings = $settings;
$this->user_flags = $user_flags; $this->user_flags = $user_flags;
$this->woocommerce_helper = $woocommerce_helper; $this->woocommerce_helper = $woocommerce_helper;
$this->wp = $wp; $this->wp = $wp;
$this->wc_transactional_emails = $wc_transactional_emails;
} }
function render() { function render() {
@ -68,6 +74,7 @@ class NewsletterEditor {
'mss_active' => Bridge::isMPSendingServiceEnabled(), 'mss_active' => Bridge::isMPSendingServiceEnabled(),
'woocommerce' => [ 'woocommerce' => [
'email_base_color' => $this->wp->getOption('woocommerce_email_base_color', '#000000'), 'email_base_color' => $this->wp->getOption('woocommerce_email_base_color', '#000000'),
'email_heading' => $this->wc_transactional_emails->getEmailHeading(),
], ],
]; ];
$this->wp->wpEnqueueMedia(); $this->wp->wpEnqueueMedia();

View File

@ -493,6 +493,14 @@ class Functions {
return wp_parse_args($args, $defaults); return wp_parse_args($args, $defaults);
} }
function wpParseUrl($url, $component = -1) {
return wp_parse_url($url, $component);
}
function wpSpecialcharsDecode($string, $quote_style = ENT_NOQUOTES ) {
return wp_specialchars_decode($string, $quote_style);
}
function wpPrintScripts($handles = false) { function wpPrintScripts($handles = false) {
return wp_print_scripts($handles); return wp_print_scripts($handles);
} }

View File

@ -21,7 +21,7 @@ class TransactionalEmails {
$this->settings = $settings; $this->settings = $settings;
} }
function init() { public function init() {
$saved_email_id = (bool)$this->settings->get(self::SETTING_EMAIL_ID, false); $saved_email_id = (bool)$this->settings->get(self::SETTING_EMAIL_ID, false);
if (!$saved_email_id) { if (!$saved_email_id) {
$email = Newsletter::createOrUpdate([ $email = Newsletter::createOrUpdate([
@ -34,6 +34,25 @@ class TransactionalEmails {
} }
} }
public function getEmailHeading() {
$default_heading = __('Thank you for your order', 'woocommerce');
$settings = $this->wp->getOption('woocommerce_customer_processing_order_settings');
if (!$settings) {
return $default_heading;
}
return $this->replacePlaceholders($settings['heading'] ?: $default_heading);
}
private function replacePlaceholders($text) {
$title = $this->wp->wpSpecialcharsDecode($this->wp->getOption('blogname'), ENT_QUOTES);
$address = $this->wp->wpParseUrl($this->wp->homeUrl(), PHP_URL_HOST);
return str_replace(
['{site_title}','{site_address}'],
[$title, $address],
$text
);
}
private function getBody() { private function getBody() {
$social_icon_url = Env::$assets_url . '/img/newsletter_editor/social-icons'; $social_icon_url = Env::$assets_url . '/img/newsletter_editor/social-icons';
$wc_header_image = $this->wp->getOption('woocommerce_email_header_image', ''); $wc_header_image = $this->wp->getOption('woocommerce_email_header_image', '');

View File

@ -1435,6 +1435,7 @@
}, },
}, },
woocommerceHeading: { woocommerceHeading: {
content: '<%= woocommerce.email_heading %>',
styles: { styles: {
fontColor: '#000000', fontColor: '#000000',
backgroundColor: '<%= woocommerce.email_base_color %>', backgroundColor: '<%= woocommerce.email_base_color %>',

View File

@ -1,11 +1,17 @@
<div class="mailpoet_tools"></div> <div class="mailpoet_tools"></div>
<style type="text/css"> <style type="text/css">
.mailpoet_editor_view_{{ viewCid }} .mailpoet_content { .mailpoet_editor_view_{{ viewCid }} .mailpoet_content {
padding: 30px 20px;
background: {{ styles.backgroundColor }}; background: {{ styles.backgroundColor }};
}
.mailpoet_editor_view_{{ viewCid }} .mailpoet_content h1 {
line-height: 1.2em;
font-family: 'Source Sans Pro';
font-size: 36px;
color: {{ styles.fontColor }}; color: {{ styles.fontColor }};
} }
</style> </style>
<div class="mailpoet_content mailpoet_woocommerce_heading" data-automation-id="woocommerce_heading"> <div class="mailpoet_content mailpoet_woocommerce_heading" data-automation-id="woocommerce_heading">
<p>This is the WC Heading Widget...</p> <h1>{{ content }}</h1>
</div> </div>
<div class="mailpoet_block_highlight"></div> <div class="mailpoet_block_highlight"></div>