Skip to content

Commit 51e2402

Browse files
committed
MAGETWO-91684: Issue with Newsletter subscriptions
- Ensure that customer id is presented.
1 parent afa59c8 commit 51e2402

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,34 @@ public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface
132132
{
133133
$storeIds = $this->storeManager->getWebsite($customer->getWebsiteId())->getStoreIds();
134134

135-
$select = $this->connection
136-
->select()
137-
->from($this->getMainTable())
138-
->where('customer_id = ?', $customer->getId())
139-
->where('store_id IN (?)', $storeIds);
140-
141-
$result = $this->connection->fetchRow($select);
142-
143-
if ($result) {
144-
return $result;
135+
if ($customer->getId()) {
136+
$select = $this->connection
137+
->select()
138+
->from($this->getMainTable())
139+
->where('customer_id = ?', $customer->getId())
140+
->where('store_id IN (?)', $storeIds)
141+
->limit(1);
142+
143+
$result = $this->connection->fetchRow($select);
144+
145+
if ($result) {
146+
return $result;
147+
}
145148
}
146149

147-
$select = $this->connection
148-
->select()
149-
->from($this->getMainTable())
150-
->where('subscriber_email = ?', $customer->getEmail())
151-
->where('store_id IN (?)', $storeIds);
150+
if ($customer->getEmail()) {
151+
$select = $this->connection
152+
->select()
153+
->from($this->getMainTable())
154+
->where('subscriber_email = ?', $customer->getEmail())
155+
->where('store_id IN (?)', $storeIds)
156+
->limit(1);
152157

153-
$result = $this->connection->fetchRow($select);
158+
$result = $this->connection->fetchRow($select);
154159

155-
if ($result) {
156-
return $result;
160+
if ($result) {
161+
return $result;
162+
}
157163
}
158164

159165
return [];

0 commit comments

Comments
 (0)