From 8b8f45269d6455f51849f028fb496cbfcbcb78b5 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Thu, 27 Jul 2023 09:24:22 -0300 Subject: [PATCH 1/5] closes #1311 change loadByEmail and loadByCustomerById magento 2.4 --- Block/Adminhtml/Customer/Edit/Tabs/View/Customer.php | 4 ++-- Block/Checkout/Success.php | 4 ++-- Block/Newsletter.php | 4 ++-- Controller/Checkout/Success.php | 4 ++-- Cron/Webhook.php | 4 ++-- Model/Api/Customer.php | 2 +- Model/Plugin/Newsletter/Save.php | 4 ++-- Model/Plugin/SubscriptionManager.php | 6 +++--- Observer/Adminhtml/Customer/SaveAfter.php | 6 +++--- Observer/Customer/SaveBefore.php | 2 +- Observer/Subscriber/SaveAfter.php | 2 +- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Block/Adminhtml/Customer/Edit/Tabs/View/Customer.php b/Block/Adminhtml/Customer/Edit/Tabs/View/Customer.php index 93c3d324..9f9bffd4 100644 --- a/Block/Adminhtml/Customer/Edit/Tabs/View/Customer.php +++ b/Block/Adminhtml/Customer/Edit/Tabs/View/Customer.php @@ -44,7 +44,7 @@ public function __construct( \Magento\Framework\Registry $registry, array $data ) { - + parent::__construct($context, $data); $this->helper = $helper; $this->subscriberFactory = $subscriberFactory; @@ -55,7 +55,7 @@ public function getInterest() { $subscriber = $this->subscriberFactory->create(); $customerId = $this->registry->registry(\Magento\Customer\Controller\RegistryConstants::CURRENT_CUSTOMER_ID); - $subscriber->loadByCustomerId($customerId); + $subscriber->loadByCustomer($customerId); return $this->helper->getSubscriberInterest($subscriber->getSubscriberId(), $subscriber->getStoreId()); } } diff --git a/Block/Checkout/Success.php b/Block/Checkout/Success.php index 8402a956..f8fd7738 100644 --- a/Block/Checkout/Success.php +++ b/Block/Checkout/Success.php @@ -52,7 +52,7 @@ public function __construct( \Ebizmarts\MailChimp\Model\MailChimpInterestGroupFactory $interestGroupFactory, array $data ) { - + parent::__construct($context, $data); $this->_checkoutSession = $checkoutSession; $this->_helper = $helper; @@ -68,7 +68,7 @@ public function getInterest() * @var $subscriber \Magento\Newsletter\Model\Subscriber */ $subscriber = $this->_subscriberFactory->create(); - $subscriber->loadByEmail($order->getCustomerEmail()); + $subscriber->loadBySubscriberEmail($order->getCustomerEmail()); return $this->_helper->getSubscriberInterest($subscriber->getSubscriberId(), $subscriber->getStoreId()); } diff --git a/Block/Newsletter.php b/Block/Newsletter.php index a12af5bb..ed15e204 100644 --- a/Block/Newsletter.php +++ b/Block/Newsletter.php @@ -43,7 +43,7 @@ public function __construct( \Ebizmarts\MailChimp\Helper\Data $helper, array $data ) { - + parent::__construct($context, $data); $this->_helper = $helper; $this->subscriberFactory = $subscriberFactory; @@ -53,7 +53,7 @@ public function __construct( public function getInterest() { $subscriber = $this->subscriberFactory->create(); - $subscriber->loadByCustomerId($this->customerSession->getCustomerId()); + $subscriber->loadByCustomer($this->customerSession->getCustomerId()); // $subscriber = $this->getSubscriptionObject(); return $this->_helper->getSubscriberInterest($subscriber->getSubscriberId(), $subscriber->getStoreId()); } diff --git a/Controller/Checkout/Success.php b/Controller/Checkout/Success.php index 139e88ff..a405a7b6 100644 --- a/Controller/Checkout/Success.php +++ b/Controller/Checkout/Success.php @@ -81,7 +81,7 @@ public function execute() $subscriber = $this->_subscriberFactory->create(); $interestGroup = $this->_interestGroupFactory->create(); try { - $subscriber->loadByEmail($order->getCustomerEmail()); + $subscriber->loadBySubscriberEmail($order->getCustomerEmail()); if ($subscriber->getEmail()==$order->getCustomerEmail()) { if ($subscriber->getStatus()==\Magento\Newsletter\Model\Subscriber::STATUS_UNSUBSCRIBED) { $subscriber->subscribe($subscriber->getEmail()); @@ -96,7 +96,7 @@ public function execute() $this->_updateSubscriber($listId, $subscriber->getId(), $this->_helper->getGmtDate(), '', 1); } else { $this->_subscriberFactory->create()->subscribe($order->getCustomerEmail()); - $subscriber->loadByEmail($order->getCustomerEmail()); + $subscriber->loadBySubscriberEmail($order->getCustomerEmail()); $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $subscriber->getStoreId()); $interestGroup->setGroupdata($this->_helper->serialize($params)); $interestGroup->setSubscriberId($subscriber->getSubscriberId()); diff --git a/Cron/Webhook.php b/Cron/Webhook.php index e4a37fd0..98c63afc 100644 --- a/Cron/Webhook.php +++ b/Cron/Webhook.php @@ -284,7 +284,7 @@ protected function _processMerges(\Magento\Customer\Model\Customer $customer, $d } $serializedGroups = $this->_helper->serialize($groups); $subscriber = $this->_subscriberFactory->create(); - $subscriber->loadByCustomerId($customer->getId()); + $subscriber->loadByCustomer($customer->getId()); $interestGroup = $this->interestGroupFactory->create(); if ($subscriber->getEmail()==$customer->getEmail()) { $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $subscriber->getStoreId()); @@ -296,7 +296,7 @@ protected function _processMerges(\Magento\Customer\Model\Customer $customer, $d $listId = $this->_helper->getGeneralList($subscriber->getStoreId()); } else { $this->_subscriberFactory->create()->subscribe($customer->getEmail()); - $subscriber->loadByEmail($customer->getEmail()); + $subscriber->loadBySubscriberEmail($customer->getEmail()); $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $subscriber->getStoreId()); $interestGroup->setGroupdata($serializedGroups); $interestGroup->setSubscriberId($subscriber->getSubscriberId()); diff --git a/Model/Api/Customer.php b/Model/Api/Customer.php index 23437e97..442cc7f1 100644 --- a/Model/Api/Customer.php +++ b/Model/Api/Customer.php @@ -185,7 +185,7 @@ protected function buildSubscriberData(\Magento\Customer\Model\Customer $custome protected function isSubscriber(\Magento\Customer\Model\Customer $customer) { $subscriber = $this->subscriberFactory->create(); - $subscriber->loadByEmail($customer->getEmail()); + $subscriber->loadBySubscriberEmail($customer->getEmail()); if ($subscriber->getEmail() == $customer->getEmail()) { if ($subscriber->getStatus() === \Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED) { return true; diff --git a/Model/Plugin/Newsletter/Save.php b/Model/Plugin/Newsletter/Save.php index 0107ac1b..af450a59 100644 --- a/Model/Plugin/Newsletter/Save.php +++ b/Model/Plugin/Newsletter/Save.php @@ -80,7 +80,7 @@ public function afterExecute() $email = $customer->getEmail(); try { - $subscriber->loadByCustomerId($this->customerSession->getCustomerId()); + $subscriber->loadByCustomer($this->customerSession->getCustomerId()); if ($subscriber->getEmail()==$email) { $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $subscriber->getStoreId()); $interestGroup->setGroupdata($this->helper->serialize($params)); @@ -92,7 +92,7 @@ public function afterExecute() $this->_updateSubscriber($listId, $subscriber->getId(), $this->helper->getGmtDate(), null, 1); } else { $this->subscriberFactory->create()->subscribe($email); - $subscriber->loadByEmail($email); + $subscriber->loadBySubscriberEmail($email); $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $subscriber->getStoreId()); $interestGroup->setGroupdata($this->helper->serialize($params)); $interestGroup->setSubscriberId($subscriber->getSubscriberId()); diff --git a/Model/Plugin/SubscriptionManager.php b/Model/Plugin/SubscriptionManager.php index 4f75c03b..70bfd10b 100644 --- a/Model/Plugin/SubscriptionManager.php +++ b/Model/Plugin/SubscriptionManager.php @@ -74,7 +74,7 @@ public function beforeUnsubscribeCustomer( ) { if ($this->_helper->isMailChimpEnabled($storeId)) { - $subscriber = $this->_subscriberFactory->create()->loadByCustomerId($customerId); + $subscriber = $this->_subscriberFactory->create()->loadByCustomer($customerId); if ($subscriber->isSubscribed()) { $api = $this->_helper->getApi($storeId); try { @@ -107,7 +107,7 @@ public function beforeSubscribeCustomer( ) { if ($this->_helper->isMailChimpEnabled($storeId)) { - $subscriber = $this->_subscriberFactory->create()->loadByCustomerId($customerId); + $subscriber = $this->_subscriberFactory->create()->loadByCustomer($customerId); if (!$subscriber->isSubscribed()) { if (!$this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAGENTO_MAIL, $storeId)) { $subscriber->setImportMode(true); @@ -221,4 +221,4 @@ public function beforeUnsubscribe( } return [$email,$storeId,$confirmCode]; } - } \ No newline at end of file + } diff --git a/Observer/Adminhtml/Customer/SaveAfter.php b/Observer/Adminhtml/Customer/SaveAfter.php index 73a560ca..b1351926 100644 --- a/Observer/Adminhtml/Customer/SaveAfter.php +++ b/Observer/Adminhtml/Customer/SaveAfter.php @@ -71,7 +71,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) } $interestGroup = $this->interestGroupFactory->create(); try { - $subscriber->loadByEmail($customer->getEmail()); + $subscriber->loadBySubscriberEmail($customer->getEmail()); if ($subscriber->getEmail() == $customer->getEmail()) { $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $subscriber->getStoreId()); $interestGroup->setGroupdata($this->helper->serialize($params)); @@ -85,7 +85,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) ); } else { $this->subscriberFactory->create()->subscribe($customer->getEmail()); - $subscriber->loadByEmail($customer->getEmail()); + $subscriber->loadBySubscriberEmail($customer->getEmail()); $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $subscriber->getStoreId()); $interestGroup->setGroupdata($this->helper->serialize($params)); $interestGroup->setSubscriberId($subscriber->getSubscriberId()); @@ -98,7 +98,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) $this->helper->log($params); } } else { - $subscriber->loadByEmail($customer->getEmail()); + $subscriber->loadBySubscriberEmail($customer->getEmail()); if ($subscriber->getEmail() == $customer->getEmail()) { $this->syncHelper->markRegisterAsModified( $subscriber->getId(), diff --git a/Observer/Customer/SaveBefore.php b/Observer/Customer/SaveBefore.php index 8e14432a..947e6aeb 100644 --- a/Observer/Customer/SaveBefore.php +++ b/Observer/Customer/SaveBefore.php @@ -70,7 +70,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) ); } $subscriber = $this->subscriberFactory->create(); - $subscriber->loadByEmail($customer->getEmail()); + $subscriber->loadBySubscriberEmail($customer->getEmail()); if ($subscriber->getEmail() == $customer->getEmail()) { $this->syncHelper->markRegisterAsModified( $subscriber->getId(), diff --git a/Observer/Subscriber/SaveAfter.php b/Observer/Subscriber/SaveAfter.php index e7631364..361a7919 100644 --- a/Observer/Subscriber/SaveAfter.php +++ b/Observer/Subscriber/SaveAfter.php @@ -60,7 +60,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) */ $factory = $this->_subscriberFactory->create(); $subscriber = $observer->getSubscriber(); - $subscriberOld = $factory->loadByCustomerId($subscriber->getCustomerId()); + $subscriberOld = $factory->loadByCustomer($subscriber->getCustomerId()); if ($this->_helper->isMailChimpEnabled($subscriberOld->getStoreId())&&$subscriberOld->getEmail()&&$subscriber->getEmail()!=$subscriberOld->getEmail()) { $api = $this->_helper->getApi($subscriberOld->getStoreId()); From 2783366384cea0817e69bcd5c7032046c5b5a30b Mon Sep 17 00:00:00 2001 From: gonzalo Date: Thu, 27 Jul 2023 14:20:03 -0300 Subject: [PATCH 2/5] closes #1311 fix loadByCustomer calls magento 2.4 --- Block/Newsletter.php | 39 ++++++++++++++++++++++++++-- Cron/Webhook.php | 2 +- Model/Plugin/Newsletter/Save.php | 2 +- Model/Plugin/SubscriptionManager.php | 4 +-- Observer/Subscriber/SaveAfter.php | 2 +- 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Block/Newsletter.php b/Block/Newsletter.php index ed15e204..6c8458f2 100644 --- a/Block/Newsletter.php +++ b/Block/Newsletter.php @@ -13,6 +13,11 @@ namespace Ebizmarts\MailChimp\Block; +use Magento\Customer\Controller\RegistryConstants; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Framework\Registry; + class Newsletter extends \Magento\Framework\View\Element\Template { /** @@ -27,13 +32,22 @@ class Newsletter extends \Magento\Framework\View\Element\Template * @var \Magento\Customer\Model\Session */ protected $customerSession; + /** + * @var CustomerRepositoryInterface + */ + private $customerRepository; + /** + * @var Registry + */ + private $registry; /** - * Newsletter constructor. * @param \Magento\Framework\View\Element\Template\Context $context * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory * @param \Ebizmarts\MailChimp\Helper\Data $helper + * @param CustomerRepositoryInterface $customerRepository + * @param Registry $registry * @param array $data */ public function __construct( @@ -41,6 +55,8 @@ public function __construct( \Magento\Customer\Model\Session $customerSession, \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory, \Ebizmarts\MailChimp\Helper\Data $helper, + CustomerRepositoryInterface $customerRepository, + Registry $registry, array $data ) { @@ -48,12 +64,15 @@ public function __construct( $this->_helper = $helper; $this->subscriberFactory = $subscriberFactory; $this->customerSession = $customerSession; + $this->customerRepository = $customerRepository; + $this->registry = $registry; } public function getInterest() { + $customer = $this->getCurrentCustomer(); $subscriber = $this->subscriberFactory->create(); - $subscriber->loadByCustomer($this->customerSession->getCustomerId()); + $subscriber->loadByCustomer($customer->getId(),$customer->getStoreId()); // $subscriber = $this->getSubscriptionObject(); return $this->_helper->getSubscriberInterest($subscriber->getSubscriberId(), $subscriber->getStoreId()); } @@ -61,4 +80,20 @@ public function getFormUrl() { return $this->getUrl('mailchimp/accountmanage/save'); } + private function getCurrentCustomer() + { + $customerId = $this->getCurrentCustomerId(); + try { + $customer = $this->customerRepository->getById($customerId); + } catch (NoSuchEntityException $e) { + return null; + } + + return $customer; + } + private function getCurrentCustomerId(): int + { + return (int)$this->registry->registry(RegistryConstants::CURRENT_CUSTOMER_ID); + } + } diff --git a/Cron/Webhook.php b/Cron/Webhook.php index 98c63afc..66ac8b41 100644 --- a/Cron/Webhook.php +++ b/Cron/Webhook.php @@ -296,7 +296,7 @@ protected function _processMerges(\Magento\Customer\Model\Customer $customer, $d $listId = $this->_helper->getGeneralList($subscriber->getStoreId()); } else { $this->_subscriberFactory->create()->subscribe($customer->getEmail()); - $subscriber->loadBySubscriberEmail($customer->getEmail()); + $subscriber->loadBySubscriberEmail($customer->getEmail(), $customer->getStoreId()); $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $subscriber->getStoreId()); $interestGroup->setGroupdata($serializedGroups); $interestGroup->setSubscriberId($subscriber->getSubscriberId()); diff --git a/Model/Plugin/Newsletter/Save.php b/Model/Plugin/Newsletter/Save.php index af450a59..cfdb2923 100644 --- a/Model/Plugin/Newsletter/Save.php +++ b/Model/Plugin/Newsletter/Save.php @@ -80,7 +80,7 @@ public function afterExecute() $email = $customer->getEmail(); try { - $subscriber->loadByCustomer($this->customerSession->getCustomerId()); + $subscriber->loadByCustomer($customer->getId(), $customer->getStoreId()); if ($subscriber->getEmail()==$email) { $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $subscriber->getStoreId()); $interestGroup->setGroupdata($this->helper->serialize($params)); diff --git a/Model/Plugin/SubscriptionManager.php b/Model/Plugin/SubscriptionManager.php index 70bfd10b..b2f0a316 100644 --- a/Model/Plugin/SubscriptionManager.php +++ b/Model/Plugin/SubscriptionManager.php @@ -74,7 +74,7 @@ public function beforeUnsubscribeCustomer( ) { if ($this->_helper->isMailChimpEnabled($storeId)) { - $subscriber = $this->_subscriberFactory->create()->loadByCustomer($customerId); + $subscriber = $this->_subscriberFactory->create()->loadByCustomer($customerId, $storeId); if ($subscriber->isSubscribed()) { $api = $this->_helper->getApi($storeId); try { @@ -107,7 +107,7 @@ public function beforeSubscribeCustomer( ) { if ($this->_helper->isMailChimpEnabled($storeId)) { - $subscriber = $this->_subscriberFactory->create()->loadByCustomer($customerId); + $subscriber = $this->_subscriberFactory->create()->loadByCustomer($customerId, $storeId); if (!$subscriber->isSubscribed()) { if (!$this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAGENTO_MAIL, $storeId)) { $subscriber->setImportMode(true); diff --git a/Observer/Subscriber/SaveAfter.php b/Observer/Subscriber/SaveAfter.php index 361a7919..8ded7d99 100644 --- a/Observer/Subscriber/SaveAfter.php +++ b/Observer/Subscriber/SaveAfter.php @@ -60,7 +60,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) */ $factory = $this->_subscriberFactory->create(); $subscriber = $observer->getSubscriber(); - $subscriberOld = $factory->loadByCustomer($subscriber->getCustomerId()); + $subscriberOld = $factory->loadByCustomer($subscriber->getCustomerId(), $subscriber->getStoreId()); if ($this->_helper->isMailChimpEnabled($subscriberOld->getStoreId())&&$subscriberOld->getEmail()&&$subscriber->getEmail()!=$subscriberOld->getEmail()) { $api = $this->_helper->getApi($subscriberOld->getStoreId()); From 0cfe6743b18000a382f15ef64ff61debd0862a77 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Thu, 27 Jul 2023 15:05:38 -0300 Subject: [PATCH 3/5] closes #1311 fix when subscriber is not customer calls magento 2.4 --- Observer/Subscriber/SaveAfter.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Observer/Subscriber/SaveAfter.php b/Observer/Subscriber/SaveAfter.php index 8ded7d99..8eb17bba 100644 --- a/Observer/Subscriber/SaveAfter.php +++ b/Observer/Subscriber/SaveAfter.php @@ -60,9 +60,13 @@ public function execute(\Magento\Framework\Event\Observer $observer) */ $factory = $this->_subscriberFactory->create(); $subscriber = $observer->getSubscriber(); - $subscriberOld = $factory->loadByCustomer($subscriber->getCustomerId(), $subscriber->getStoreId()); - - if ($this->_helper->isMailChimpEnabled($subscriberOld->getStoreId())&&$subscriberOld->getEmail()&&$subscriber->getEmail()!=$subscriberOld->getEmail()) { +// $subscriberOld = $factory->loadByCustomer($subscriber->getCustomerId(), $subscriber->getStoreId()); + $isCustomer = $subscriber->getCustomerId(); + if ($isCustomer) { + $subscriberOld = $factory->loadBySubscriberEmail($subscriber->getCustomerId(), $subscriber->getStoreId()); + } + if ($this->_helper->isMailChimpEnabled($subscriberOld->getStoreId())&&$isCustomer&& + $subscriberOld->getEmail()&&$subscriber->getEmail()!=$subscriberOld->getEmail()) { $api = $this->_helper->getApi($subscriberOld->getStoreId()); $mergeVars = $this->_helper->getMergeVarsBySubscriber($subscriberOld, $subscriberOld->getEmail()); $status = 'unsubscribed'; From 67c234bde2b9912cd312121f12510aa266f80637 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Thu, 27 Jul 2023 15:21:41 -0300 Subject: [PATCH 4/5] closes #1311 fix when subscriber is not customer calls magento 2.4 --- Observer/Subscriber/SaveAfter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Observer/Subscriber/SaveAfter.php b/Observer/Subscriber/SaveAfter.php index 8eb17bba..3c055a17 100644 --- a/Observer/Subscriber/SaveAfter.php +++ b/Observer/Subscriber/SaveAfter.php @@ -65,7 +65,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) if ($isCustomer) { $subscriberOld = $factory->loadBySubscriberEmail($subscriber->getCustomerId(), $subscriber->getStoreId()); } - if ($this->_helper->isMailChimpEnabled($subscriberOld->getStoreId())&&$isCustomer&& + if ($this->_helper->isMailChimpEnabled($subscriber->getStoreId())&&$isCustomer&& $subscriberOld->getEmail()&&$subscriber->getEmail()!=$subscriberOld->getEmail()) { $api = $this->_helper->getApi($subscriberOld->getStoreId()); $mergeVars = $this->_helper->getMergeVarsBySubscriber($subscriberOld, $subscriberOld->getEmail()); From f824b81d2c97332f402510e2c797360e92f10ac6 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Thu, 27 Jul 2023 17:17:34 -0300 Subject: [PATCH 5/5] closes #1311 fix loadBySubscriberEmail calls magento 2.4 --- Block/Checkout/Success.php | 2 +- Controller/Checkout/Success.php | 4 ++-- Model/Api/Customer.php | 2 +- Model/Plugin/Newsletter/Save.php | 2 +- Observer/Adminhtml/Customer/SaveAfter.php | 6 +++--- Observer/Customer/SaveBefore.php | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Block/Checkout/Success.php b/Block/Checkout/Success.php index f8fd7738..1ce60e30 100644 --- a/Block/Checkout/Success.php +++ b/Block/Checkout/Success.php @@ -68,7 +68,7 @@ public function getInterest() * @var $subscriber \Magento\Newsletter\Model\Subscriber */ $subscriber = $this->_subscriberFactory->create(); - $subscriber->loadBySubscriberEmail($order->getCustomerEmail()); + $subscriber->loadBySubscriberEmail($order->getCustomerEmail(), $order->getStoreId()); return $this->_helper->getSubscriberInterest($subscriber->getSubscriberId(), $subscriber->getStoreId()); } diff --git a/Controller/Checkout/Success.php b/Controller/Checkout/Success.php index a405a7b6..8a7ba4cd 100644 --- a/Controller/Checkout/Success.php +++ b/Controller/Checkout/Success.php @@ -81,7 +81,7 @@ public function execute() $subscriber = $this->_subscriberFactory->create(); $interestGroup = $this->_interestGroupFactory->create(); try { - $subscriber->loadBySubscriberEmail($order->getCustomerEmail()); + $subscriber->loadBySubscriberEmail($order->getCustomerEmail(), $order->getStoreId()); if ($subscriber->getEmail()==$order->getCustomerEmail()) { if ($subscriber->getStatus()==\Magento\Newsletter\Model\Subscriber::STATUS_UNSUBSCRIBED) { $subscriber->subscribe($subscriber->getEmail()); @@ -96,7 +96,7 @@ public function execute() $this->_updateSubscriber($listId, $subscriber->getId(), $this->_helper->getGmtDate(), '', 1); } else { $this->_subscriberFactory->create()->subscribe($order->getCustomerEmail()); - $subscriber->loadBySubscriberEmail($order->getCustomerEmail()); + $subscriber->loadBySubscriberEmail($order->getCustomerEmail(), $order->getStoreId()); $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $subscriber->getStoreId()); $interestGroup->setGroupdata($this->_helper->serialize($params)); $interestGroup->setSubscriberId($subscriber->getSubscriberId()); diff --git a/Model/Api/Customer.php b/Model/Api/Customer.php index 442cc7f1..e0900981 100644 --- a/Model/Api/Customer.php +++ b/Model/Api/Customer.php @@ -185,7 +185,7 @@ protected function buildSubscriberData(\Magento\Customer\Model\Customer $custome protected function isSubscriber(\Magento\Customer\Model\Customer $customer) { $subscriber = $this->subscriberFactory->create(); - $subscriber->loadBySubscriberEmail($customer->getEmail()); + $subscriber->loadBySubscriberEmail($customer->getEmail(), $customer->getStoreId()); if ($subscriber->getEmail() == $customer->getEmail()) { if ($subscriber->getStatus() === \Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED) { return true; diff --git a/Model/Plugin/Newsletter/Save.php b/Model/Plugin/Newsletter/Save.php index cfdb2923..64e4b0a5 100644 --- a/Model/Plugin/Newsletter/Save.php +++ b/Model/Plugin/Newsletter/Save.php @@ -92,7 +92,7 @@ public function afterExecute() $this->_updateSubscriber($listId, $subscriber->getId(), $this->helper->getGmtDate(), null, 1); } else { $this->subscriberFactory->create()->subscribe($email); - $subscriber->loadBySubscriberEmail($email); + $subscriber->loadBySubscriberEmail($email, $customer->getStoreId()); $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $subscriber->getStoreId()); $interestGroup->setGroupdata($this->helper->serialize($params)); $interestGroup->setSubscriberId($subscriber->getSubscriberId()); diff --git a/Observer/Adminhtml/Customer/SaveAfter.php b/Observer/Adminhtml/Customer/SaveAfter.php index b1351926..6db0431e 100644 --- a/Observer/Adminhtml/Customer/SaveAfter.php +++ b/Observer/Adminhtml/Customer/SaveAfter.php @@ -71,7 +71,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) } $interestGroup = $this->interestGroupFactory->create(); try { - $subscriber->loadBySubscriberEmail($customer->getEmail()); + $subscriber->loadBySubscriberEmail($customer->getEmail(), $customer->getStoreId()); if ($subscriber->getEmail() == $customer->getEmail()) { $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $subscriber->getStoreId()); $interestGroup->setGroupdata($this->helper->serialize($params)); @@ -85,7 +85,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) ); } else { $this->subscriberFactory->create()->subscribe($customer->getEmail()); - $subscriber->loadBySubscriberEmail($customer->getEmail()); + $subscriber->loadBySubscriberEmail($customer->getEmail(), $customer->getStoreId()); $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $subscriber->getStoreId()); $interestGroup->setGroupdata($this->helper->serialize($params)); $interestGroup->setSubscriberId($subscriber->getSubscriberId()); @@ -98,7 +98,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) $this->helper->log($params); } } else { - $subscriber->loadBySubscriberEmail($customer->getEmail()); + $subscriber->loadBySubscriberEmail($customer->getEmail(), $customer->getStoreId()); if ($subscriber->getEmail() == $customer->getEmail()) { $this->syncHelper->markRegisterAsModified( $subscriber->getId(), diff --git a/Observer/Customer/SaveBefore.php b/Observer/Customer/SaveBefore.php index 947e6aeb..772272ef 100644 --- a/Observer/Customer/SaveBefore.php +++ b/Observer/Customer/SaveBefore.php @@ -70,7 +70,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) ); } $subscriber = $this->subscriberFactory->create(); - $subscriber->loadBySubscriberEmail($customer->getEmail()); + $subscriber->loadBySubscriberEmail($customer->getEmail(), $customer->getStoreId()); if ($subscriber->getEmail() == $customer->getEmail()) { $this->syncHelper->markRegisterAsModified( $subscriber->getId(),