55 */
66namespace Magento \Newsletter \Model \ResourceModel ;
77
8+ use Magento \Store \Model \StoreManagerInterface ;
9+ use Magento \Framework \App \ObjectManager ;
10+
811/**
912 * Newsletter subscriber resource model
1013 *
@@ -48,22 +51,33 @@ class Subscriber extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
4851 */
4952 protected $ mathRandom ;
5053
54+ /**
55+ * Store manager
56+ *
57+ * @var StoreManagerInterface
58+ */
59+ private $ storeManager ;
60+
5161 /**
5262 * Construct
5363 *
5464 * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
5565 * @param \Magento\Framework\Stdlib\DateTime\DateTime $date
5666 * @param \Magento\Framework\Math\Random $mathRandom
5767 * @param string $connectionName
68+ * @param StoreManagerInterface $storeManager
5869 */
5970 public function __construct (
6071 \Magento \Framework \Model \ResourceModel \Db \Context $ context ,
6172 \Magento \Framework \Stdlib \DateTime \DateTime $ date ,
6273 \Magento \Framework \Math \Random $ mathRandom ,
63- $ connectionName = null
74+ $ connectionName = null ,
75+ StoreManagerInterface $ storeManager = null
6476 ) {
6577 $ this ->_date = $ date ;
6678 $ this ->mathRandom = $ mathRandom ;
79+ $ this ->storeManager = $ storeManager ?: ObjectManager::getInstance ()
80+ ->get (StoreManagerInterface::class);
6781 parent ::__construct ($ context , $ connectionName );
6882 }
6983
@@ -118,6 +132,9 @@ public function loadByEmail($subscriberEmail)
118132 */
119133 public function loadByCustomerData (\Magento \Customer \Api \Data \CustomerInterface $ customer )
120134 {
135+ $ storeId = (int )$ customer ->getStoreId () ?: $ this ->storeManager
136+ ->getWebsite ($ customer ->getWebsiteId ())->getDefaultStore ()->getId ();
137+
121138 $ select = $ this ->connection
122139 ->select ()
123140 ->from ($ this ->getMainTable ())
@@ -128,7 +145,7 @@ public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface
128145 $ select ,
129146 [
130147 'customer_id ' => $ customer ->getId (),
131- 'store_id ' => $ customer -> getStoreId ()
148+ 'store_id ' => $ storeId
132149 ]
133150 );
134151
@@ -146,7 +163,7 @@ public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface
146163 $ select ,
147164 [
148165 'subscriber_email ' => $ customer ->getEmail (),
149- 'store_id ' => $ customer -> getStoreId ()
166+ 'store_id ' => $ storeId
150167 ]
151168 );
152169
0 commit comments