Skip to content

Commit 65000d8

Browse files
committed
Fix newsletter subscriptions between stores
Include store_id in query result in order to ensure that the action (subscribe/unsubscribe) it’s done in the correct store.
1 parent 13a933a commit 65000d8

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
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;

0 commit comments

Comments
 (0)