From ee1d2e75b6675ca38f70fc5c58527a8d00c92542 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Fri, 8 Mar 2019 16:26:43 -0300 Subject: [PATCH] closes #645 for magento 2.1 --- Helper/Data.php | 9 +++++++++ Model/Plugin/AccountManagement.php | 13 ++++++++++--- etc/adminhtml/system.xml | 8 ++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index 24276054..b14588e9 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -38,6 +38,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper const XML_ABANDONEDCART_FIRSTDATE = 'mailchimp/abandonedcart/firstdate'; const XML_ABANDONEDCART_PAGE = 'mailchimp/abandonedcart/page'; const XML_PATH_IS_SYNC = 'mailchimp/general/issync'; + const XML_ABANDONEDCART_EMAIL = 'mailchimp/abandonedcart/save_email_in_quote'; const XML_MERGEVARS = 'mailchimp/general/map_fields'; const XML_INTEREST = 'mailchimp/general/interest'; const XML_INTEREST_IN_SUCCESS = 'mailchimp/general/interest_in_success'; @@ -1134,4 +1135,12 @@ public function unserialize($string) } return $result; } + public function isEmailSavingEnabled($storeId) + { + return $this->_scopeConfig->isSetFlag( + self::XML_ABANDONEDCART_EMAIL, + \Magento\Store\Model\ScopeInterface::SCOPE_STORES, + $storeId + ); + } } diff --git a/Model/Plugin/AccountManagement.php b/Model/Plugin/AccountManagement.php index 64696327..f365ebf0 100644 --- a/Model/Plugin/AccountManagement.php +++ b/Model/Plugin/AccountManagement.php @@ -27,22 +27,29 @@ class AccountManagement * @var \Magento\Quote\Model\QuoteFactory */ protected $_quote; + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $_storeManager; /** * AccountManagement constructor. * @param \Ebizmarts\MailChimp\Helper\Data $helper - * @param \Magento\Checkout\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Quote\Model\QuoteFactory $quote + * @param \Magento\Store\Model\StoreManagerInterface $storeManager */ public function __construct( \Ebizmarts\MailChimp\Helper\Data $helper, \Magento\Checkout\Model\Session $checkoutSession, - \Magento\Quote\Model\QuoteFactory $quote + \Magento\Quote\Model\QuoteFactory $quote, + \Magento\Store\Model\StoreManagerInterface $storeManager ) { $this->_helper = $helper; $this->_quote = $quote; $this->_session = $checkoutSession; + $this->_storeManager = $storeManager; } /** @@ -59,7 +66,7 @@ public function aroundIsEmailAvailable( ) { $ret = $proceed($customerEmail,$websiteId); - if ($this->_session) { + if ($this->_session && $this->_helper->isEmailSavingEnabled($this->_storeManager->getStore()->getId())) { $quoteId = $this->_session->getQuoteId(); if ($quoteId) { $quote = $this->_quote->create(); diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 7b17e008..e97b290d 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -230,6 +230,14 @@ 1 + + + Select No to prevent saving customer Email to the quote before Order was placed + Magento\Config\Model\Config\Source\Yesno + + 1 + +