diff --git a/assets/js/src/newsletter_editor/blocks/products.js b/assets/js/src/newsletter_editor/blocks/products.js index 96b24abf80..f7c01a45f2 100644 --- a/assets/js/src/newsletter_editor/blocks/products.js +++ b/assets/js/src/newsletter_editor/blocks/products.js @@ -548,6 +548,9 @@ Module.ProductsWidgetView = base.WidgetView.extend({ }); App.on('before:start', function beforeStartApp(BeforeStartApp) { + if (!window.mailpoet_woocommerce_active) { + return; + } BeforeStartApp.registerBlockType('products', { blockModel: Module.ProductsBlockModel, blockView: Module.ProductsBlockView, diff --git a/lib/Twig/Functions.php b/lib/Twig/Functions.php index 72ba89581a..5c4f28a385 100644 --- a/lib/Twig/Functions.php +++ b/lib/Twig/Functions.php @@ -6,6 +6,7 @@ use Carbon\Carbon; use MailPoet\Config\ServicesChecker; use MailPoet\Settings\SettingsController; use MailPoet\Util\FreeDomains; +use MailPoet\WooCommerce\Helper as WooCommerceHelper; use MailPoet\WP\Functions as WPFunctions; use MailPoetVendor\Twig\Extension\AbstractExtension; use MailPoetVendor\Twig\TwigFunction; @@ -17,8 +18,12 @@ class Functions extends AbstractExtension { /** @var SettingsController */ private $settings; + /** @var WooCommerceHelper */ + private $woocommerce_helper; + public function __construct() { $this->settings = new SettingsController(); + $this->woocommerce_helper = new WooCommerceHelper(); } function getFunctions() { @@ -118,6 +123,11 @@ class Functions extends AbstractExtension { array($this, 'getFreeDomains'), array('is_safe' => array('all')) ), + new TwigFunction( + 'is_woocommerce_active', + array($this, 'isWoocommerceActive'), + array('is_safe' => array('all')) + ), ); } @@ -211,4 +221,8 @@ class Functions extends AbstractExtension { function getFreeDomains() { return FreeDomains::FREE_DOMAINS; } + + function isWoocommerceActive() { + return $this->woocommerce_helper->isWooCommerceActive(); + } } diff --git a/tests/acceptance/EditorProductsCest.php b/tests/acceptance/EditorProductsCest.php index 42dd1e06be..4e2ca8178d 100644 --- a/tests/acceptance/EditorProductsCest.php +++ b/tests/acceptance/EditorProductsCest.php @@ -45,7 +45,7 @@ class EditorProductsCest { $I->clickItemRowActionByItemName($this->newsletterTitle, 'Edit'); $I->waitForText('Spacer'); - $I->waitForElementVisible('#automation_editor_block_products'); + $I->waitForElementNotVisible('#automation_editor_block_products'); } private function initializeWooCommerce(\AcceptanceTester $I) { diff --git a/views/layout.html b/views/layout.html index 4b816d5a38..8aabe208fe 100644 --- a/views/layout.html +++ b/views/layout.html @@ -54,6 +54,7 @@ jQuery('.toplevel_page_mailpoet-newsletters.menu-top-last') var mailpoet_analytics_public_id = <%= json_encode(get_analytics_public_id()) %>; var mailpoet_analytics_new_public_id = <%= is_analytics_public_id_new() | json_encode %>; var mailpoet_free_domains = <%= json_encode(mailpoet_free_domains()) %>; + var mailpoet_woocommerce_active = <%= json_encode(is_woocommerce_active()) %>; // RFC 5322 standard; http://emailregex.com/ combined with https://google.github.io/closure-library/api/goog.format.EmailAddress.html#isValid var mailpoet_email_regex = /(?=^[+a-zA-Z0-9_.!#$%&'*\/=?^`{|}~-]+@([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,63}$)(?=^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,})))/;