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
@@ -117,6 +131,9 @@ public function loadByEmail($subscriberEmail)
117131 */
118132 public function loadByCustomerData (\Magento \Customer \Api \Data \CustomerInterface $ customer )
119133 {
134+ $ storeId = (int )$ customer ->getStoreId () ?: $ this ->storeManager
135+ ->getWebsite ($ customer ->getWebsiteId ())->getDefaultStore ()->getId ();
136+
120137 $ select = $ this ->connection
121138 ->select ()
122139 ->from ($ this ->getMainTable ())
@@ -127,7 +144,7 @@ public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface
127144 $ select ,
128145 [
129146 'customer_id ' => $ customer ->getId (),
130- 'store_id ' => $ customer -> getStoreId ()
147+ 'store_id ' => $ storeId
131148 ]
132149 );
133150
@@ -145,7 +162,7 @@ public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface
145162 $ select ,
146163 [
147164 'subscriber_email ' => $ customer ->getEmail (),
148- 'store_id ' => $ customer -> getStoreId ()
165+ 'store_id ' => $ storeId
149166 ]
150167 );
151168
0 commit comments