Skip to content

Commit

Permalink
Merge pull request #648 from mailchimp/Issue645-2.1
Browse files Browse the repository at this point in the history
closes #645 for magento 2.1
  • Loading branch information
gonzaloebiz authored Mar 8, 2019
2 parents 6c3ac25 + ee1d2e7 commit c1bf0b4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
9 changes: 9 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
);
}
}
13 changes: 10 additions & 3 deletions Model/Plugin/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@
<field id="*/*/active">1</field>
</depends>
</field>
<field id="save_email_in_quote" translate="label comment" sortOrder="50" type="select" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Save Email to the Quote before place Order</label>
<comment>Select No to prevent saving customer Email to the quote before Order was placed</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="*/*/active">1</field>
</depends>
</field>
</group>
</section>
</system>
Expand Down

0 comments on commit c1bf0b4

Please sign in to comment.