Add Coupon block feature flag
[MAILPOET-4678]
This commit is contained in:
@@ -7,6 +7,9 @@ import { BaseBlock } from 'newsletter_editor/blocks/base';
|
|||||||
import _ from 'underscore';
|
import _ from 'underscore';
|
||||||
import jQuery from 'jquery';
|
import jQuery from 'jquery';
|
||||||
import 'backbone.marionette';
|
import 'backbone.marionette';
|
||||||
|
import { MailPoet } from '../../mailpoet';
|
||||||
|
|
||||||
|
export const FEATURE_COUPON_BLOCK = 'Coupon block';
|
||||||
|
|
||||||
const Module: Record<string, (...args: unknown[]) => void> = {};
|
const Module: Record<string, (...args: unknown[]) => void> = {};
|
||||||
const base = BaseBlock;
|
const base = BaseBlock;
|
||||||
@@ -232,7 +235,10 @@ Module.CouponWidgetView = base.WidgetView.extend({
|
|||||||
});
|
});
|
||||||
|
|
||||||
App.on('before:start', (BeforeStartApp) => {
|
App.on('before:start', (BeforeStartApp) => {
|
||||||
if (!window.MailPoet.isWoocommerceActive) {
|
if (
|
||||||
|
!MailPoet.FeaturesController.isSupported(FEATURE_COUPON_BLOCK) ||
|
||||||
|
!window.MailPoet.isWoocommerceActive
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BeforeStartApp.registerBlockType('coupon', {
|
BeforeStartApp.registerBlockType('coupon', {
|
||||||
|
@@ -9,11 +9,14 @@ class FeaturesController {
|
|||||||
|
|
||||||
const FEATURE_LANDINGPAGE = 'landingpage';
|
const FEATURE_LANDINGPAGE = 'landingpage';
|
||||||
|
|
||||||
|
const FEATURE_COUPON_BLOCK = 'Coupon block';
|
||||||
|
|
||||||
// Define feature defaults in the array below in the following form:
|
// Define feature defaults in the array below in the following form:
|
||||||
// self::FEATURE_NAME_OF_FEATURE => true,
|
// self::FEATURE_NAME_OF_FEATURE => true,
|
||||||
private $defaults = [
|
private $defaults = [
|
||||||
self::FEATURE_HOMEPAGE => false,
|
self::FEATURE_HOMEPAGE => false,
|
||||||
self::FEATURE_LANDINGPAGE => false,
|
self::FEATURE_LANDINGPAGE => false,
|
||||||
|
self::FEATURE_COUPON_BLOCK => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var array|null */
|
/** @var array|null */
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
namespace MailPoet\Newsletter\Renderer;
|
namespace MailPoet\Newsletter\Renderer;
|
||||||
|
|
||||||
use MailPoet\Entities\NewsletterEntity;
|
use MailPoet\Entities\NewsletterEntity;
|
||||||
|
use MailPoet\Features\FeaturesController;
|
||||||
use MailPoet\Newsletter\Renderer\Blocks\AbandonedCartContent;
|
use MailPoet\Newsletter\Renderer\Blocks\AbandonedCartContent;
|
||||||
use MailPoet\Newsletter\Renderer\Blocks\AutomatedLatestContentBlock;
|
use MailPoet\Newsletter\Renderer\Blocks\AutomatedLatestContentBlock;
|
||||||
use MailPoet\Tasks\Sending as SendingTask;
|
use MailPoet\Tasks\Sending as SendingTask;
|
||||||
@@ -31,16 +32,21 @@ class Preprocessor {
|
|||||||
/*** @var CouponPreProcessor */
|
/*** @var CouponPreProcessor */
|
||||||
private $couponPreProcessor;
|
private $couponPreProcessor;
|
||||||
|
|
||||||
|
/*** @var FeaturesController */
|
||||||
|
private $featuresController;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AbandonedCartContent $abandonedCartContent,
|
AbandonedCartContent $abandonedCartContent,
|
||||||
AutomatedLatestContentBlock $automatedLatestContent,
|
AutomatedLatestContentBlock $automatedLatestContent,
|
||||||
ContentPreprocessor $wooCommerceContentPreprocessor,
|
ContentPreprocessor $wooCommerceContentPreprocessor,
|
||||||
CouponPreProcessor $couponPreProcessor
|
CouponPreProcessor $couponPreProcessor,
|
||||||
|
FeaturesController $featuresController
|
||||||
) {
|
) {
|
||||||
$this->abandonedCartContent = $abandonedCartContent;
|
$this->abandonedCartContent = $abandonedCartContent;
|
||||||
$this->automatedLatestContent = $automatedLatestContent;
|
$this->automatedLatestContent = $automatedLatestContent;
|
||||||
$this->wooCommerceContentPreprocessor = $wooCommerceContentPreprocessor;
|
$this->wooCommerceContentPreprocessor = $wooCommerceContentPreprocessor;
|
||||||
$this->couponPreProcessor = $couponPreProcessor;
|
$this->couponPreProcessor = $couponPreProcessor;
|
||||||
|
$this->featuresController = $featuresController;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,7 +60,9 @@ class Preprocessor {
|
|||||||
}
|
}
|
||||||
$blocks = [];
|
$blocks = [];
|
||||||
$contentBlocks = $content['blocks'];
|
$contentBlocks = $content['blocks'];
|
||||||
$contentBlocks = $this->couponPreProcessor->processCoupons($newsletter, $contentBlocks, $preview);
|
if ($this->featuresController->isSupported(FeaturesController::FEATURE_COUPON_BLOCK)) {
|
||||||
|
$contentBlocks = $this->couponPreProcessor->processCoupons($newsletter, $contentBlocks, $preview);
|
||||||
|
}
|
||||||
foreach ($contentBlocks as $block) {
|
foreach ($contentBlocks as $block) {
|
||||||
$processedBlock = $this->processBlock($newsletter, $block, $preview, $sendingTask);
|
$processedBlock = $this->processBlock($newsletter, $block, $preview, $sendingTask);
|
||||||
if (!empty($processedBlock)) {
|
if (!empty($processedBlock)) {
|
||||||
|
@@ -5,6 +5,7 @@ namespace MailPoet\WooCommerce\TransactionalEmails;
|
|||||||
use Codeception\Stub;
|
use Codeception\Stub;
|
||||||
use MailPoet\Config\ServicesChecker;
|
use MailPoet\Config\ServicesChecker;
|
||||||
use MailPoet\Entities\NewsletterEntity;
|
use MailPoet\Entities\NewsletterEntity;
|
||||||
|
use MailPoet\Features\FeaturesController;
|
||||||
use MailPoet\Models\Newsletter;
|
use MailPoet\Models\Newsletter;
|
||||||
use MailPoet\Newsletter\Editor\LayoutHelper as L;
|
use MailPoet\Newsletter\Editor\LayoutHelper as L;
|
||||||
use MailPoet\Newsletter\NewslettersRepository;
|
use MailPoet\Newsletter\NewslettersRepository;
|
||||||
@@ -110,7 +111,8 @@ class RendererTest extends \MailPoetTest {
|
|||||||
$this->diContainer->get(\MailPoet\Newsletter\Renderer\Blocks\AbandonedCartContent::class),
|
$this->diContainer->get(\MailPoet\Newsletter\Renderer\Blocks\AbandonedCartContent::class),
|
||||||
$this->diContainer->get(\MailPoet\Newsletter\Renderer\Blocks\AutomatedLatestContentBlock::class),
|
$this->diContainer->get(\MailPoet\Newsletter\Renderer\Blocks\AutomatedLatestContentBlock::class),
|
||||||
$wooPreprocessor,
|
$wooPreprocessor,
|
||||||
$this->diContainer->get(\MailPoet\WooCommerce\CouponPreProcessor::class)
|
$this->diContainer->get(\MailPoet\WooCommerce\CouponPreProcessor::class),
|
||||||
|
$this->diContainer->get(FeaturesController::class)
|
||||||
),
|
),
|
||||||
$this->diContainer->get(\MailPoetVendor\CSS::class),
|
$this->diContainer->get(\MailPoetVendor\CSS::class),
|
||||||
$this->diContainer->get(ServicesChecker::class),
|
$this->diContainer->get(ServicesChecker::class),
|
||||||
|
@@ -4,6 +4,7 @@ namespace MailPoet\Test\Newsletter;
|
|||||||
|
|
||||||
use Codeception\Stub;
|
use Codeception\Stub;
|
||||||
use MailPoet\Entities\NewsletterEntity;
|
use MailPoet\Entities\NewsletterEntity;
|
||||||
|
use MailPoet\Features\FeaturesController;
|
||||||
use MailPoet\Newsletter\Renderer\Blocks\AbandonedCartContent;
|
use MailPoet\Newsletter\Renderer\Blocks\AbandonedCartContent;
|
||||||
use MailPoet\Newsletter\Renderer\Blocks\AutomatedLatestContentBlock;
|
use MailPoet\Newsletter\Renderer\Blocks\AutomatedLatestContentBlock;
|
||||||
use MailPoet\Newsletter\Renderer\Preprocessor;
|
use MailPoet\Newsletter\Renderer\Preprocessor;
|
||||||
@@ -22,7 +23,8 @@ class PreprocessorTest extends \MailPoetUnitTest {
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$wooPreprocessor = new TransactionalEmails\ContentPreprocessor($transactionalEmails);
|
$wooPreprocessor = new TransactionalEmails\ContentPreprocessor($transactionalEmails);
|
||||||
$preprocessor = new Preprocessor($acc, $alc, $wooPreprocessor, $couponPreProcessor);
|
$featuresController = Stub::make(FeaturesController::class);
|
||||||
|
$preprocessor = new Preprocessor($acc, $alc, $wooPreprocessor, $couponPreProcessor, $featuresController);
|
||||||
expect($preprocessor->processBlock(new NewsletterEntity(), ['type' => 'woocommerceHeading']))->equals([[
|
expect($preprocessor->processBlock(new NewsletterEntity(), ['type' => 'woocommerceHeading']))->equals([[
|
||||||
'type' => 'container',
|
'type' => 'container',
|
||||||
'orientation' => 'horizontal',
|
'orientation' => 'horizontal',
|
||||||
@@ -50,7 +52,8 @@ class PreprocessorTest extends \MailPoetUnitTest {
|
|||||||
$alc = Stub::make(AutomatedLatestContentBlock::class);
|
$alc = Stub::make(AutomatedLatestContentBlock::class);
|
||||||
$couponPreProcessor = Stub::make(CouponPreProcessor::class);
|
$couponPreProcessor = Stub::make(CouponPreProcessor::class);
|
||||||
$wooPreprocessor = new TransactionalEmails\ContentPreprocessor(Stub::make(TransactionalEmails::class));
|
$wooPreprocessor = new TransactionalEmails\ContentPreprocessor(Stub::make(TransactionalEmails::class));
|
||||||
$preprocessor = new Preprocessor($acc, $alc, $wooPreprocessor, $couponPreProcessor);
|
$featuresController = Stub::make(FeaturesController::class);
|
||||||
|
$preprocessor = new Preprocessor($acc, $alc, $wooPreprocessor, $couponPreProcessor, $featuresController);
|
||||||
expect($preprocessor->processBlock(new NewsletterEntity(), ['type' => 'woocommerceContent']))->equals([[
|
expect($preprocessor->processBlock(new NewsletterEntity(), ['type' => 'woocommerceContent']))->equals([[
|
||||||
'type' => 'container',
|
'type' => 'container',
|
||||||
'orientation' => 'horizontal',
|
'orientation' => 'horizontal',
|
||||||
|
Reference in New Issue
Block a user