Skip to content

Commit 806add0

Browse files
committed
Merge remote-tracking branch 'github-magento2ce/MAGETWO-91684' into EPAM-PR-18
2 parents b1c9ac4 + 51e2402 commit 806add0

File tree

2 files changed

+31
-36
lines changed

2 files changed

+31
-36
lines changed

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

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
namespace Magento\Newsletter\Model\ResourceModel;
77

8-
use Magento\Store\Model\StoreManagerInterface;
98
use Magento\Framework\App\ObjectManager;
9+
use Magento\Store\Model\StoreManagerInterface;
1010

1111
/**
1212
* Newsletter subscriber resource model
@@ -76,8 +76,7 @@ public function __construct(
7676
) {
7777
$this->_date = $date;
7878
$this->mathRandom = $mathRandom;
79-
$this->storeManager = $storeManager ?: ObjectManager::getInstance()
80-
->get(StoreManagerInterface::class);
79+
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
8180
parent::__construct($context, $connectionName);
8281
}
8382

@@ -131,43 +130,36 @@ public function loadByEmail($subscriberEmail)
131130
*/
132131
public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer)
133132
{
134-
$storeId = (int)$customer->getStoreId() ?: $this->storeManager
135-
->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
136-
137-
$select = $this->connection
138-
->select()
139-
->from($this->getMainTable())
140-
->where('customer_id=:customer_id and store_id=:store_id');
141-
142-
$result = $this->connection
143-
->fetchRow(
144-
$select,
145-
[
146-
'customer_id' => $customer->getId(),
147-
'store_id' => $storeId
148-
]
149-
);
133+
$storeIds = $this->storeManager->getWebsite($customer->getWebsiteId())->getStoreIds();
134+
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);
150142

151-
if ($result) {
152-
return $result;
143+
$result = $this->connection->fetchRow($select);
144+
145+
if ($result) {
146+
return $result;
147+
}
153148
}
154149

155-
$select = $this->connection
156-
->select()
157-
->from($this->getMainTable())
158-
->where('subscriber_email=:subscriber_email and store_id=:store_id');
159-
160-
$result = $this->connection
161-
->fetchRow(
162-
$select,
163-
[
164-
'subscriber_email' => $customer->getEmail(),
165-
'store_id' => $storeId
166-
]
167-
);
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);
157+
158+
$result = $this->connection->fetchRow($select);
168159

169-
if ($result) {
170-
return $result;
160+
if ($result) {
161+
return $result;
162+
}
171163
}
172164

173165
return [];

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ public function loadByCustomerId($customerId)
392392
try {
393393
$customerData = $this->customerRepository->getById($customerId);
394394
$customerData->setStoreId($this->_storeManager->getStore()->getId());
395+
if ($customerData->getWebsiteId() === null) {
396+
$customerData->setWebsiteId($this->_storeManager->getStore()->getWebsiteId());
397+
}
395398
$data = $this->getResource()->loadByCustomerData($customerData);
396399
$this->addData($data);
397400
if (!empty($data) && $customerData->getId() && !$this->getCustomerId()) {

0 commit comments

Comments
 (0)