Skip to content

Commit 39ed21f

Browse files
Merge forwardport of #12035 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/12035.patch (created by @sbaixauli) based on commit(s): 1. 65000d8 2. 81725aa 3. 19fe0df 4. 2e2f66b 5. 194ba57 Fixed GitHub Issues in 2.3-develop branch: - #10014: Newsletter subscriptions status not isolated between multi stores (reported by @mikelevy300)
2 parents 617da6c + 8b1a297 commit 39ed21f

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

app/code/Magento/Newsletter/Model/ResourceModel/Subscriber.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,37 @@ public function loadByEmail($subscriberEmail)
118118
*/
119119
public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer)
120120
{
121-
$select = $this->connection->select()->from($this->getMainTable())->where('customer_id=:customer_id');
122-
123-
$result = $this->connection->fetchRow($select, ['customer_id' => $customer->getId()]);
121+
$select = $this->connection
122+
->select()
123+
->from($this->getMainTable())
124+
->where('customer_id=:customer_id and store_id=:store_id');
125+
126+
$result = $this->connection
127+
->fetchRow(
128+
$select,
129+
[
130+
'customer_id' => $customer->getId(),
131+
'store_id' => $customer->getStoreId()
132+
]
133+
);
124134

125135
if ($result) {
126136
return $result;
127137
}
128138

129-
$select = $this->connection->select()->from($this->getMainTable())->where('subscriber_email=:subscriber_email');
130-
131-
$result = $this->connection->fetchRow($select, ['subscriber_email' => $customer->getEmail()]);
139+
$select = $this->connection
140+
->select()
141+
->from($this->getMainTable())
142+
->where('subscriber_email=:subscriber_email and store_id=:store_id');
143+
144+
$result = $this->connection
145+
->fetchRow(
146+
$select,
147+
[
148+
'subscriber_email' => $customer->getEmail(),
149+
'store_id' => $customer->getStoreId()
150+
]
151+
);
132152

133153
if ($result) {
134154
return $result;

app/code/Magento/Newsletter/Model/Subscriber.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ public function loadByCustomerId($customerId)
349349
{
350350
try {
351351
$customerData = $this->customerRepository->getById($customerId);
352+
$customerData->setStoreId($this->_storeManager->getStore()->getId());
352353
$data = $this->getResource()->loadByCustomerData($customerData);
353354
$this->addData($data);
354355
if (!empty($data) && $customerData->getId() && !$this->getCustomerId()) {

app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ public function testUpdateSubscription()
187187
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
188188
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
189189

190+
$storeModel = $this->getMockBuilder(\Magento\Store\Model\Store::class)
191+
->disableOriginalConstructor()
192+
->setMethods(['getId'])
193+
->getMock();
194+
$this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel);
195+
190196
$this->assertEquals($this->subscriber, $this->subscriber->updateSubscription($customerId));
191197
}
192198

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/IndexTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ public function testSaveActionExistingCustomerUnsubscribeNewsletter()
347347
'email' => '[email protected]',
348348
'firstname' => 'test firstname',
349349
'lastname' => 'test lastname',
350+
'sendemail_store_id' => 1
350351
],
351352
'subscription' => '0'
352353
];

dev/tests/integration/testsuite/Magento/Newsletter/_files/subscribers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
$subscriber = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
3030
->create(\Magento\Newsletter\Model\Subscriber::class);
31-
$subscriber->setStoreId($otherStore)
31+
$subscriber->setStoreId($currentStore)
3232
// Intentionally setting ID to 0 instead of 2 to test fallback mechanism in Subscriber model
3333
->setCustomerId(0)
3434
->setSubscriberEmail('[email protected]')

0 commit comments

Comments
 (0)