diff --git a/Block/Popup.php b/Block/Popup.php
index ce9ae42..2490834 100644
--- a/Block/Popup.php
+++ b/Block/Popup.php
@@ -24,6 +24,7 @@
use Magento\Catalog\Block\Product\AbstractProduct;
use Magento\Catalog\Block\Product\Context;
use Magento\Framework\Phrase;
+use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory;
use Magento\Widget\Block\BlockInterface;
use Mageplaza\BetterPopup\Helper\Data as HelperData;
@@ -42,6 +43,11 @@ class Popup extends AbstractProduct implements BlockInterface
*/
protected $_helperData;
+ /**
+ * @var TimezoneInterface
+ */
+ protected $_localeDate;
+
/**
* @var CollectionFactory
*/
@@ -52,51 +58,24 @@ class Popup extends AbstractProduct implements BlockInterface
*
* @param Context $context
* @param HelperData $helperData
+ * @param TimezoneInterface $localeDate
* @param CollectionFactory $subscriberCollectionFactory
* @param array $data
*/
public function __construct(
Context $context,
HelperData $helperData,
+ TimezoneInterface $localeDate,
CollectionFactory $subscriberCollectionFactory,
array $data = []
) {
- $this->_helperData = $helperData;
+ $this->_helperData = $helperData;
+ $this->_localeDate = $localeDate;
$this->_subscriberCollectionFactory = $subscriberCollectionFactory;
parent::__construct($context, $data);
}
- /**
- * Get Width Popup Config
- *
- * @return array|mixed
- */
- public function getWidthPopup()
- {
- return $this->_helperData->getWhatToShowConfig('width');
- }
-
- /**
- * Get Height Popup Config
- *
- * @return array|mixed
- */
- public function getHeightPopup()
- {
- return $this->_helperData->getWhatToShowConfig('height');
- }
-
- /**
- * Get Background Color Popup
- *
- * @return array|mixed
- */
- public function getBackGroundColor()
- {
- return $this->_helperData->getWhatToShowConfig('background_color');
- }
-
/**
* Get Text Color in Popup
*
@@ -107,26 +86,6 @@ public function getTextColor()
return $this->_helperData->getWhatToShowConfig('text_color');
}
- /**
- * Check FullScreen option
- *
- * @return bool
- */
- public function isFullScreen()
- {
- return (int)$this->_helperData->getWhatToShowConfig('responsive') === Responsive::FULLSCREEN_POPUP;
- }
-
- /**
- * Check show fireworks config
- *
- * @return bool
- */
- public function isShowFireworks()
- {
- return $this->_helperData->getWhatToShowConfig('popup_success/enabled_fireworks');
- }
-
/**
* Is Enable Show Float Button
*
@@ -159,62 +118,6 @@ public function getFloatLabel()
return $label ?: __('Subscribe');
}
- /**
- * Get Config Popup Appear
- *
- * @return array|mixed
- */
- public function getPopupAppear()
- {
- return (int)$this->_helperData->getWhenToShowConfig('popup_appear');
- }
-
- /**
- * Get time delay to show popup
- *
- * @return array|int|mixed
- */
- public function getDelayConfig()
- {
- if ($this->getPopupAppear() === Appear::AFTER_X_SECONDS) {
- return $this->_helperData->getWhenToShowConfig('delay');
- }
-
- return 0;
- }
-
- /**
- * is Exit Intent Config
- *
- * @return string
- */
- public function isExitIntent()
- {
- return $this->getPopupAppear() === Appear::EXIT_INTENT;
- }
-
- /**
- * Get Popup show again after (days)
- *
- * @return array|mixed
- */
- public function getCookieConfig()
- {
- $cookieDays = $this->_helperData->getWhenToShowConfig('cookieExp');
-
- return ($cookieDays !== null) ? $cookieDays : 30;
- }
-
- /**
- * Get Percentage scroll down to show Popup
- *
- * @return array|mixed
- */
- public function getPercentageScroll()
- {
- return $this->_helperData->getWhenToShowConfig('after_scroll');
- }
-
/**
* Get Html Content popup
*
@@ -224,7 +127,7 @@ public function getPopupContent()
{
$htmlConfig = $this->_helperData->getWhatToShowConfig('html_content');
- $search = [
+ $search = [
'{{form_url}}',
'{{url_loader}}',
'{{email_icon_url}}',
@@ -255,40 +158,50 @@ public function getPopupContent()
}
/**
- * Check include pages are show Popup
+ * Get Url NewAction Newsletter
*
+ * @return string
+ */
+ public function getFormActionUrl()
+ {
+ return $this->getUrl('newsletter/subscriber/new', ['_secure' => true]);
+ }
+
+ /**
* @return bool
*/
- public function checkIncludePages()
+ public function checkBetterMaintenance()
{
- $fullActionName = $this->getRequest()->getFullActionName();
- $arrayPages = explode("\n", $this->_helperData->getWhereToShowConfig('include_pages'));
- $includePages = array_map('trim', $arrayPages);
+ if ($this->_helperData->getBetterMaintenanceConfigGeneral('enabled') === '1') {
+ if (strtotime($this->_localeDate->date()->format('m/d/Y H:i:s'))
+ < strtotime($this->_helperData->getBetterMaintenanceConfigGeneral('end_time'))) {
+ return false;
+ }
+ }
- return in_array($fullActionName, $includePages, true);
+ return true;
}
/**
- * Check include paths to show popup
+ * check Manually Insert Config
*
* @return bool
*/
- public function checkIncludePaths()
+ public function isManuallyInsert()
{
- $currentPath = $this->getRequest()->getRequestUri();
- $pathsConfig = $this->_helperData->getWhereToShowConfig('include_pages_with_url');
-
- if ($pathsConfig) {
- $arrayPaths = explode("\n", $pathsConfig);
- $pathsUrl = array_map('trim', $arrayPaths);
- foreach ($pathsUrl as $path) {
- if ($path && strpos($currentPath, $path) !== false) {
- return true;
- }
- }
- }
+ return $this->_helperData->isEnabled()
+ && (int)$this->_helperData->getWhereToShowConfig('which_page_to_show') === PageToShow::MANUALLY_INSERT
+ && $this->checkExclude();
+ }
- return false;
+ /**
+ * Check Exclude (page & path)
+ *
+ * @return bool
+ */
+ public function checkExclude()
+ {
+ return ($this->checkExcludePages() && $this->checkExcludePaths());
}
/**
@@ -299,8 +212,8 @@ public function checkIncludePaths()
public function checkExcludePages()
{
$fullActionName = $this->getRequest()->getFullActionName();
- $arrayPages = explode("\n", $this->_helperData->getWhereToShowConfig('exclude_pages'));
- $includePages = array_map('trim', $arrayPages);
+ $arrayPages = explode("\n", $this->_helperData->getWhereToShowConfig('exclude_pages'));
+ $includePages = array_map('trim', $arrayPages);
return !in_array($fullActionName, $includePages, true);
}
@@ -317,7 +230,7 @@ public function checkExcludePaths()
if ($pathsConfig) {
$arrayPaths = explode("\n", $pathsConfig);
- $pathsUrl = array_map('trim', $arrayPaths);
+ $pathsUrl = array_map('trim', $arrayPaths);
foreach ($pathsUrl as $path) {
if (strpos($currentPath, $path) !== false) {
@@ -330,54 +243,69 @@ public function checkExcludePaths()
}
/**
- * Check Include (page & path)
+ * Check Pages to show popup
*
* @return bool
*/
- public function checkInclude()
+ public function checkPagesToShow()
{
- return ($this->checkIncludePages() || $this->checkIncludePaths());
+ if ($this->_helperData->isEnabled()) {
+ $config = $this->_helperData->getWhereToShowConfig('which_page_to_show');
+
+ switch ($config) {
+ case PageToShow::SPECIFIC_PAGES:
+ return ($this->checkInclude() && $this->checkExclude());
+ case PageToShow::ALL_PAGES:
+ return $this->checkExclude();
+ case PageToShow::MANUALLY_INSERT:
+ return false;
+ }
+ }
+
+ return false;
}
/**
- * Check Exclude (page & path)
+ * Check Include (page & path)
*
* @return bool
*/
- public function checkExclude()
+ public function checkInclude()
{
- return ($this->checkExcludePages() && $this->checkExcludePaths());
+ return ($this->checkIncludePages() || $this->checkIncludePaths());
}
/**
- * check Manually Insert Config
+ * Check include pages are show Popup
*
* @return bool
*/
- public function isManuallyInsert()
+ public function checkIncludePages()
{
- return $this->_helperData->isEnabled()
- && (int)$this->_helperData->getWhereToShowConfig('which_page_to_show') === PageToShow::MANUALLY_INSERT
- && $this->checkExclude();
+ $fullActionName = $this->getRequest()->getFullActionName();
+ $arrayPages = explode("\n", $this->_helperData->getWhereToShowConfig('include_pages'));
+ $includePages = array_map('trim', $arrayPages);
+
+ return in_array($fullActionName, $includePages, true);
}
/**
- * Check Pages to show popup
+ * Check include paths to show popup
*
* @return bool
*/
- public function checkPagesToShow()
+ public function checkIncludePaths()
{
- if ($this->_helperData->isEnabled()) {
- $config = $this->_helperData->getWhereToShowConfig('which_page_to_show');
+ $currentPath = $this->getRequest()->getRequestUri();
+ $pathsConfig = $this->_helperData->getWhereToShowConfig('include_pages_with_url');
- switch ($config) {
- case PageToShow::SPECIFIC_PAGES:
- return ($this->checkInclude() && $this->checkExclude());
- case PageToShow::ALL_PAGES:
- return $this->checkExclude();
- case PageToShow::MANUALLY_INSERT:
- return false;
+ if ($pathsConfig) {
+ $arrayPaths = explode("\n", $pathsConfig);
+ $pathsUrl = array_map('trim', $arrayPaths);
+ foreach ($pathsUrl as $path) {
+ if ($path && strpos($currentPath, $path) !== false) {
+ return true;
+ }
}
}
@@ -392,39 +320,136 @@ public function checkPagesToShow()
public function getAjaxData()
{
$params = [
- 'url' => $this->getUrl('betterpopup/ajax/success'),
- 'isScroll' => $this->getPopupAppear() === Appear::AFTER_SCROLL_DOWN,
- 'afterSeconds' => [
+ 'url' => $this->getUrl('betterpopup/ajax/success'),
+ 'isScroll' => $this->getPopupAppear() === Appear::AFTER_SCROLL_DOWN,
+ 'afterSeconds' => [
'isAfterSeconds' => $this->getPopupAppear() === Appear::AFTER_X_SECONDS,
- 'delay' => $this->getDelayConfig()
+ 'delay' => $this->getDelayConfig()
],
- 'percentage' => $this->getPercentageScroll(),
- 'fullScreen' => [
+ 'percentage' => $this->getPercentageScroll(),
+ 'fullScreen' => [
'isFullScreen' => $this->isFullScreen(),
- 'bgColor' => $this->getBackGroundColor()
+ 'bgColor' => $this->getBackGroundColor()
],
- 'isExitIntent' => $this->isExitIntent(),
- 'isShowFireworks' => $this->isShowFireworks(),
- 'popupConfig' => [
- 'width' => $this->getWidthPopup(),
- 'height' => $this->getHeightPopup(),
- 'cookieExp' => $this->getCookieConfig(),
- 'delay' => $this->getDelayConfig(),
+ 'isExitIntent' => $this->isExitIntent(),
+ 'isShowPopupSuccess' => $this->_helperData->getWhatToShowConfig('popup_success/enabled'),
+ 'isShowFireworks' => $this->isShowFireworks(),
+ 'popupConfig' => [
+ 'width' => $this->getWidthPopup(),
+ 'height' => $this->getHeightPopup(),
+ 'cookieExp' => $this->getCookieConfig(),
+ 'delay' => $this->getDelayConfig(),
'showOnDelay' => true,
],
- 'srcCloseIconWhite' => $this->getViewFileUrl('Mageplaza_BetterPopup::images/icon-close-white.png')
+ 'srcCloseIconWhite' => $this->getViewFileUrl('Mageplaza_BetterPopup::images/icon-close-white.png')
];
return HelperData::jsonEncode($params);
}
/**
- * Get Url NewAction Newsletter
+ * Get Config Popup Appear
+ *
+ * @return array|mixed
+ */
+ public function getPopupAppear()
+ {
+ return (int)$this->_helperData->getWhenToShowConfig('popup_appear');
+ }
+
+ /**
+ * Get time delay to show popup
+ *
+ * @return array|int|mixed
+ */
+ public function getDelayConfig()
+ {
+ if ($this->getPopupAppear() === Appear::AFTER_X_SECONDS) {
+ return $this->_helperData->getWhenToShowConfig('delay');
+ }
+
+ return 0;
+ }
+
+ /**
+ * Get Percentage scroll down to show Popup
+ *
+ * @return array|mixed
+ */
+ public function getPercentageScroll()
+ {
+ return $this->_helperData->getWhenToShowConfig('after_scroll');
+ }
+
+ /**
+ * Check FullScreen option
+ *
+ * @return bool
+ */
+ public function isFullScreen()
+ {
+ return (int)$this->_helperData->getWhatToShowConfig('responsive') === Responsive::FULLSCREEN_POPUP;
+ }
+
+ /**
+ * Get Background Color Popup
+ *
+ * @return array|mixed
+ */
+ public function getBackGroundColor()
+ {
+ return $this->_helperData->getWhatToShowConfig('background_color');
+ }
+
+ /**
+ * is Exit Intent Config
*
* @return string
*/
- public function getFormActionUrl()
+ public function isExitIntent()
{
- return $this->getUrl('newsletter/subscriber/new', ['_secure' => true]);
+ return $this->getPopupAppear() === Appear::EXIT_INTENT;
+ }
+
+ /**
+ * Check show fireworks config
+ *
+ * @return bool
+ */
+ public function isShowFireworks()
+ {
+ return $this->_helperData->getWhatToShowConfig('popup_success/enabled_fireworks');
+ }
+
+ /**
+ * Get Width Popup Config
+ *
+ * @return array|mixed
+ */
+ public function getWidthPopup()
+ {
+ return $this->_helperData->getWhatToShowConfig('width');
+ }
+
+ /**
+ * Get Height Popup Config
+ *
+ * @return array|mixed
+ */
+ public function getHeightPopup()
+ {
+ return $this->_helperData->getWhatToShowConfig('height');
+ }
+
+ /**
+ * Get Popup show again after (days)
+ *
+ * @return array|mixed
+ */
+ public function getCookieConfig()
+ {
+ $cookieDays = $this->_helperData->getWhenToShowConfig('cookieExp');
+
+ return ($cookieDays !== null) ? $cookieDays : 30;
}
}
diff --git a/Block/Success.php b/Block/Success.php
index 9248a9d..9cc22aa 100644
--- a/Block/Success.php
+++ b/Block/Success.php
@@ -23,6 +23,7 @@
use Magento\Catalog\Block\Product\Context;
use Magento\Framework\Exception\LocalizedException;
+use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory;
use Mageplaza\BetterPopup\Helper\Data as HelperData;
use Mageplaza\BetterPopup\Model\Generate;
@@ -41,9 +42,9 @@ class Success extends Popup
/**
* Success constructor.
- *
* @param Context $context
* @param HelperData $helperData
+ * @param TimezoneInterface $localeDate
* @param CollectionFactory $subscriberCollectionFactory
* @param Generate $generate
* @param array $data
@@ -51,11 +52,12 @@ class Success extends Popup
public function __construct(
Context $context,
HelperData $helperData,
+ TimezoneInterface $localeDate,
CollectionFactory $subscriberCollectionFactory,
Generate $generate,
array $data = []
) {
- parent::__construct($context, $helperData, $subscriberCollectionFactory, $data);
+ parent::__construct($context, $helperData, $localeDate, $subscriberCollectionFactory, $data);
$this->generate = $generate;
}
diff --git a/Helper/Data.php b/Helper/Data.php
index 84daa8c..e4462b5 100644
--- a/Helper/Data.php
+++ b/Helper/Data.php
@@ -64,12 +64,25 @@ public function __construct(
Filesystem $filesystem,
DirectoryList $directoryList
) {
- $this->_fileSystem = $filesystem;
+ $this->_fileSystem = $filesystem;
$this->_directoryList = $directoryList;
parent::__construct($context, $objectManager, $storeManager);
}
+ /**
+ * @param string $code
+ * @param null $storeId
+ *
+ * @return array|mixed
+ */
+ public function getBetterMaintenanceConfigGeneral($code = '', $storeId = null)
+ {
+ $code = ($code !== '') ? '/' . $code : '';
+
+ return $this->getConfigValue('mpbettermaintenance/general' . $code, $storeId);
+ }
+
/**
* @param $code
* @param null $storeId
@@ -104,24 +117,24 @@ public function getWhenToShowConfig($code, $storeId = null)
}
/**
- * @param $code
* @param null $storeId
*
* @return mixed
*/
- public function getSendEmailConfig($code, $storeId = null)
+ public function isSendEmail($storeId = null)
{
- return $this->getModuleConfig('send_email/' . $code, $storeId);
+ return $this->getSendEmailConfig('isSendEmail', $storeId);
}
/**
+ * @param $code
* @param null $storeId
*
* @return mixed
*/
- public function isSendEmail($storeId = null)
+ public function getSendEmailConfig($code, $storeId = null)
{
- return $this->getSendEmailConfig('isSendEmail', $storeId);
+ return $this->getModuleConfig('send_email/' . $code, $storeId);
}
/**
@@ -134,6 +147,30 @@ public function getToEmail()
return $this->getSendEmailConfig('to');
}
+ /**
+ * @param $templateId
+ *
+ * @return string
+ * @throws FileSystemException
+ */
+ public function getDefaultTemplateHtml($templateId)
+ {
+ return $this->readFile($this->getTemplatePath($templateId));
+ }
+
+ /**
+ * @param $relativePath
+ *
+ * @return string
+ * @throws FileSystemException
+ */
+ public function readFile($relativePath)
+ {
+ $rootDirectory = $this->_fileSystem->getDirectoryRead(DirectoryList::ROOT);
+
+ return $rootDirectory->readFile($relativePath);
+ }
+
/**
* Get default template path
*
@@ -151,17 +188,17 @@ public function getTemplatePath($templateId, $type = '.html')
$rootPath = $this->_directoryList->getRoot();
$currentDirArr = explode('\\', $currentDir);
- $countDir = count($currentDirArr);
+ $countDir = count($currentDirArr);
if ($countDir === 1) {
$currentDirArr = explode('/', $currentDir);
- $countDir = count($currentDirArr);
+ $countDir = count($currentDirArr);
}
$rootPathArr = explode('/', $rootPath);
- $countPath = count($rootPathArr);
+ $countPath = count($rootPathArr);
if ($countPath === 1) {
$rootPathArr = explode('\\', $rootPath);
- $countPath = count($rootPathArr);
+ $countPath = count($rootPathArr);
}
$basePath = '';
@@ -174,30 +211,6 @@ public function getTemplatePath($templateId, $type = '.html')
return $templatePath . $templateId . $type;
}
- /**
- * @param $relativePath
- *
- * @return string
- * @throws FileSystemException
- */
- public function readFile($relativePath)
- {
- $rootDirectory = $this->_fileSystem->getDirectoryRead(DirectoryList::ROOT);
-
- return $rootDirectory->readFile($relativePath);
- }
-
- /**
- * @param $templateId
- *
- * @return string
- * @throws FileSystemException
- */
- public function getDefaultTemplateHtml($templateId)
- {
- return $this->readFile($this->getTemplatePath($templateId));
- }
-
/**
* @return int
* @throws NoSuchEntityException
diff --git a/Plugin/Controller/Subscriber/NewAction.php b/Plugin/Controller/Subscriber/NewAction.php
index 74669d2..2a27ba9 100644
--- a/Plugin/Controller/Subscriber/NewAction.php
+++ b/Plugin/Controller/Subscriber/NewAction.php
@@ -22,10 +22,19 @@
namespace Mageplaza\BetterPopup\Plugin\Controller\Subscriber;
use Exception;
+use Magento\Customer\Api\AccountManagementInterface as CustomerAccountManagement;
+use Magento\Customer\Model\Session;
+use Magento\Customer\Model\Url as CustomerUrl;
+use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Exception\LocalizedException;
+use Magento\Framework\Phrase;
+use Magento\Framework\Validator\EmailAddress as EmailValidator;
+use Magento\Newsletter\Model\Subscriber;
use Magento\Newsletter\Model\SubscriberFactory;
+use Magento\Newsletter\Model\SubscriptionManagerInterface;
+use Magento\Store\Model\StoreManagerInterface;
use Mageplaza\BetterPopup\Helper\Data;
/**
@@ -44,6 +53,53 @@ class NewAction extends \Magento\Newsletter\Controller\Subscriber\NewAction
*/
protected $_helperData;
+ /**
+ * @var SubscriptionManagerInterface
+ */
+ protected $subscriberManagerInterface;
+
+ /**
+ * NewAction constructor.
+ *
+ * @param Context $context
+ * @param SubscriberFactory $subscriberFactory
+ * @param Session $customerSession
+ * @param StoreManagerInterface $storeManager
+ * @param CustomerUrl $customerUrl
+ * @param CustomerAccountManagement $customerAccountManagement
+ * @param SubscriptionManagerInterface $subscriptionManager
+ * @param JsonFactory $jsonFactory
+ * @param Data $helperData
+ * @param EmailValidator|null $emailValidator
+ */
+ public function __construct(
+ Context $context,
+ SubscriberFactory $subscriberFactory,
+ Session $customerSession,
+ StoreManagerInterface $storeManager,
+ CustomerUrl $customerUrl,
+ CustomerAccountManagement $customerAccountManagement,
+ SubscriptionManagerInterface $subscriptionManager,
+ JsonFactory $jsonFactory,
+ Data $helperData,
+ EmailValidator $emailValidator = null
+ ) {
+ $this->resultJsonFactory = $jsonFactory;
+ $this->_helperData = $helperData;
+ $this->subscriberManagerInterface = $subscriptionManager;
+
+ parent::__construct(
+ $context,
+ $subscriberFactory,
+ $customerSession,
+ $storeManager,
+ $customerUrl,
+ $customerAccountManagement,
+ $subscriptionManager,
+ $emailValidator
+ );
+ }
+
/**
* @param $subject
* @param $proceed
@@ -52,10 +108,7 @@ class NewAction extends \Magento\Newsletter\Controller\Subscriber\NewAction
*/
public function aroundExecute($subject, $proceed)
{
- $resultJsonFactory = ObjectManager::getInstance()->get(JsonFactory::class);
- $_helperData = ObjectManager::getInstance()->get(Data::class);
-
- if (!$_helperData->isEnabled() || !$this->getRequest()->isAjax()) {
+ if (!$this->_helperData->isEnabled() || !$this->getRequest()->isAjax()) {
return $proceed();
}
@@ -68,25 +121,77 @@ public function aroundExecute($subject, $proceed)
$this->validateGuestSubscription();
$this->validateEmailAvailable($email);
- $this->_subscriberFactory->create()->subscribe($email);
- if (!$_helperData->versionCompare('2.2.0')) {
- $this->_subscriberFactory->create()
- ->loadByEmail($email)
- ->setChangeStatusAt(date('Y-m-d h:i:s'))->save();
+ $websiteId = (int)$this->_storeManager->getStore()->getWebsiteId();
+ $subscriber = $this->_subscriberFactory->create()->loadBySubscriberEmail($email, $websiteId);
+ if ($subscriber->getId()
+ && (int)$subscriber->getSubscriberStatus() === Subscriber::STATUS_SUBSCRIBED) {
+ $response = [
+ 'success' => false,
+ 'msg' => __('This email address is already subscribed.')
+ ];
+
+ return $this->resultJsonFactory->create()->setData($response);
}
+ $storeId = (int)$this->_storeManager->getStore()->getId();
+ $currentCustomerId = $this->getSessionCustomerId($email);
+ $subscriber = $currentCustomerId
+ ? $this->subscriberManagerInterface->subscribeCustomer($currentCustomerId, $storeId)
+ : $this->subscriberManagerInterface->subscribe($email, $storeId);
+ $message = $this->getSuccessMessage((int)$subscriber->getSubscriberStatus());
+ $response = [
+ 'success' => true,
+ 'msg' => $message,
+ ];
} catch (LocalizedException $e) {
$response = [
- 'success' => true,
- 'msg' => __('There was a problem with the subscription: %1', $e->getMessage()),
+ 'success' => false,
+ 'msg' => __('There was a problem with the subscription: %1', $e->getMessage()),
];
} catch (Exception $e) {
$response = [
- 'status' => 'ERROR',
- 'msg' => __('Something went wrong with the subscription: %1', $e->getMessage()),
+ 'status' => false,
+ 'msg' => __('Something went wrong with the subscription: %1', $e->getMessage()),
];
}
}
- return $resultJsonFactory->create()->setData($response);
+ return $this->resultJsonFactory->create()->setData($response);
+ }
+
+ /**
+ * Get customer id from session if he is owner of the email
+ *
+ * @param string $email
+ *
+ * @return int|null
+ */
+ private function getSessionCustomerId(string $email): ?int
+ {
+ if (!$this->_customerSession->isLoggedIn()) {
+ return null;
+ }
+
+ $customer = $this->_customerSession->getCustomerDataObject();
+ if ($customer->getEmail() !== $email) {
+ return null;
+ }
+
+ return (int)$this->_customerSession->getId();
+ }
+
+ /**
+ * Get success message
+ *
+ * @param int $status
+ *
+ * @return Phrase
+ */
+ private function getSuccessMessage(int $status): Phrase
+ {
+ if ($status === Subscriber::STATUS_NOT_ACTIVE) {
+ return __('The confirmation request has been sent.');
+ }
+
+ return __('Thank you for your subscription.');
}
}
diff --git a/composer.json b/composer.json
index 8dca74e..c7cde71 100644
--- a/composer.json
+++ b/composer.json
@@ -5,7 +5,7 @@
"mageplaza/module-core": "^1.4.5"
},
"type": "magento2-module",
- "version": "4.0.0",
+ "version": "4.1.0",
"license": "proprietary",
"authors": [
{
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index 22af01c..4ed9918 100755
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -1,246 +1,249 @@
-
-
-
- 2. How to setup abandoned cart email series]]>
- The rule should be set as a Specific Coupon and Auto-generated.
- Learn more
- ]]>
-
- Separated by a new line
- ]]>
-
- Separated by a new line
- ]]>
-
+ The rule should be set as a Specific Coupon and Auto-generated.
+ Learn more
+ ]]>
+
+ Separated by a new line
+ ]]>
+
+ Separated by a new line
+ ]]>
+
-