From 8b184b4107110fefa7bde7623533086a3c473d03 Mon Sep 17 00:00:00 2001 From: vprohorov Date: Thu, 26 Jul 2018 17:33:04 +0300 Subject: [PATCH 1/2] MAGETWO-91701: Newsletter subscription is not correctly updated when user is registered on 2 stores - Adding additional checking for guest customers --- .../Model/ResourceModel/Subscriber.php | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber.php b/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber.php index c7ce4b2f2f11b..4e059f9fe79a0 100644 --- a/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber.php +++ b/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber.php @@ -48,6 +48,13 @@ class Subscriber extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb */ protected $mathRandom; + /** + * Guest customer id + * + * @var int + */ + private $guestCustomerId = 0; + /** * Construct * @@ -136,22 +143,24 @@ public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface return $result; } - $select = $this->connection - ->select() - ->from($this->getMainTable()) - ->where('subscriber_email=:subscriber_email and store_id=:store_id'); - - $result = $this->connection - ->fetchRow( - $select, - [ - 'subscriber_email' => $customer->getEmail(), - 'store_id' => $customer->getStoreId() - ] - ); - - if ($result) { - return $result; + if ($customer->getId() === $this->guestCustomerId) { + $select = $this->connection + ->select() + ->from($this->getMainTable()) + ->where('subscriber_email=:subscriber_email and store_id=:store_id'); + + $result = $this->connection + ->fetchRow( + $select, + [ + 'subscriber_email' => $customer->getEmail(), + 'store_id' => $customer->getStoreId() + ] + ); + + if ($result) { + return $result; + } } return []; From e3a9ac2ea24ba7c2ab83ee4d1253397ce7ebf61b Mon Sep 17 00:00:00 2001 From: David Grigoryan Date: Thu, 9 Aug 2018 10:57:15 +0400 Subject: [PATCH 2/2] MAGETWO-91701: Newsletter subscription is not correctly updated when user is registered on 2 stores - Add automated test --- ...bscribedNewsletterDisplayedActionGroup.xml | 162 ++++++++++++++++++ ...erifySubscribedNewsletterDisplayedData.xml | 23 +++ ...fySubscribedNewsLetterDisplayedSection.xml | 80 +++++++++ ...erifySubscribedNewsletterDisplayedTest.xml | 65 +++++++ 4 files changed, 330 insertions(+) create mode 100644 app/code/Magento/Newsletter/Test/Mftf/ActionGroup/VerifySubscribedNewsletterDisplayedActionGroup.xml create mode 100644 app/code/Magento/Newsletter/Test/Mftf/Data/VerifySubscribedNewsletterDisplayedData.xml create mode 100644 app/code/Magento/Newsletter/Test/Mftf/Section/VerifySubscribedNewsLetterDisplayedSection.xml create mode 100644 app/code/Magento/Newsletter/Test/Mftf/Test/VerifySubscribedNewsletterDisplayedTest.xml diff --git a/app/code/Magento/Newsletter/Test/Mftf/ActionGroup/VerifySubscribedNewsletterDisplayedActionGroup.xml b/app/code/Magento/Newsletter/Test/Mftf/ActionGroup/VerifySubscribedNewsletterDisplayedActionGroup.xml new file mode 100644 index 0000000000000..1f61e1dab9813 --- /dev/null +++ b/app/code/Magento/Newsletter/Test/Mftf/ActionGroup/VerifySubscribedNewsletterDisplayedActionGroup.xml @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Newsletter/Test/Mftf/Data/VerifySubscribedNewsletterDisplayedData.xml b/app/code/Magento/Newsletter/Test/Mftf/Data/VerifySubscribedNewsletterDisplayedData.xml new file mode 100644 index 0000000000000..4082626cef5a7 --- /dev/null +++ b/app/code/Magento/Newsletter/Test/Mftf/Data/VerifySubscribedNewsletterDisplayedData.xml @@ -0,0 +1,23 @@ + + + + + + + + store2 + + + + John + Smith + Admin@123 + + + \ No newline at end of file diff --git a/app/code/Magento/Newsletter/Test/Mftf/Section/VerifySubscribedNewsLetterDisplayedSection.xml b/app/code/Magento/Newsletter/Test/Mftf/Section/VerifySubscribedNewsLetterDisplayedSection.xml new file mode 100644 index 0000000000000..1af5c142e2cd7 --- /dev/null +++ b/app/code/Magento/Newsletter/Test/Mftf/Section/VerifySubscribedNewsLetterDisplayedSection.xml @@ -0,0 +1,80 @@ + + + + + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + + + + + +
+ +
+ + + + + +
+ +
+ + + + + + + +
+ +
+ + + +
+ +
+ + + + + + + +
+ +
\ No newline at end of file diff --git a/app/code/Magento/Newsletter/Test/Mftf/Test/VerifySubscribedNewsletterDisplayedTest.xml b/app/code/Magento/Newsletter/Test/Mftf/Test/VerifySubscribedNewsletterDisplayedTest.xml new file mode 100644 index 0000000000000..78c4e2085cc86 --- /dev/null +++ b/app/code/Magento/Newsletter/Test/Mftf/Test/VerifySubscribedNewsletterDisplayedTest.xml @@ -0,0 +1,65 @@ + + + + + + + + + + <description value="Newsletter subscription when user is registered on 2 stores"/> + <severity value="MAJOR"/> + <testCaseId value="MAGETWO-93836"/> + </annotations> + + <before> + <!--Log in to Magento as admin.--> + <actionGroup ref="LoginActionGroup" stepKey="login"/> + <!--Go to Stores.--> + <actionGroup ref="GoToAllStores" stepKey="goToAllStores"/> + <!--Create Website.--> + <actionGroup ref="AdminCreateWebsite" stepKey="adminCreateWebsite"/> + <!--Create Store.--> + <actionGroup ref="AdminCreateNewStore" stepKey="adminCreateNewStore"/> + <!--Create Store View.--> + <actionGroup ref="AdminCreateStoreView" stepKey="adminCreateStoreView"/> + <!--Go to Stores -> Configuration -> Web.--> + <actionGroup ref="GoToStoresConfigurationWeb" stepKey="goToStoresConfigurationWeb"/> + <actionGroup ref="SelectYesInAddStoreCodeToUrlsField" stepKey="selectYesInAddStoreCodeToUrlsField"/> + </before> + + <!--Go to store front (default) and click Create an Account.--> + <amOnPage url="{{StorefrontCustomerCreatePage.url}}" stepKey="navigateToCustomers"/> + <actionGroup ref="StorefrontCreateNewAccount" stepKey="createNewAccount"/> + + <!--Sign Out--> + <actionGroup ref="StorefrontSignOut" stepKey="storefrontSignOut"/> + + <!--Change 'default' to 'url_name' in url--> + <amOnPage url="{{AdminTestData.testData}}" stepKey="goToCreatedWebPage"/> + <waitForPageLoad stepKey="waitForCreatedWebPageLoaded"/> + + <!--Create new Account with the same email address. (unchecked Sign Up for Newsletter checkbox)--> + <actionGroup ref="StorefrontCreateNewAccountNewsletterUnchecked" stepKey="createNewAccountNewsletterUnchecked"/> + <dontSee stepKey="verifySubscribedNewsletters" userInput="You aren't subscribed to our newsletter displayed"/> + + <after> + <!--Delete created data and set Default Configuration--> + <amOnPage url="admin" stepKey="goToAdminPage"/> + <waitForPageLoad stepKey="waitForAdminPageLoaded"/> + <actionGroup ref="AdminDeleteCreatedCustomer" stepKey="adminDeleteCustomer"/> + <actionGroup ref="GoToAllStores" stepKey="goToAllStores"/> + <actionGroup ref="AdminDeleteWebsite" stepKey="adminDeleteWebsite"/> + <actionGroup ref="GoToStoresConfigurationWeb" stepKey="goToStoresConfigurationWeb"/> + <actionGroup ref="AdminSetDefaultConfig" stepKey="adminSetDefaultConfig"/> + </after> + + </test> +</tests> +