5
5
*/
6
6
namespace Magento \Newsletter \Model \ResourceModel ;
7
7
8
+ use Magento \Store \Model \StoreManagerInterface ;
9
+ use Magento \Framework \App \ObjectManager ;
10
+
8
11
/**
9
12
* Newsletter subscriber resource model
10
13
*
@@ -48,22 +51,33 @@ class Subscriber extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
48
51
*/
49
52
protected $ mathRandom ;
50
53
54
+ /**
55
+ * Store manager
56
+ *
57
+ * @var StoreManagerInterface
58
+ */
59
+ private $ storeManager ;
60
+
51
61
/**
52
62
* Construct
53
63
*
54
64
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
55
65
* @param \Magento\Framework\Stdlib\DateTime\DateTime $date
56
66
* @param \Magento\Framework\Math\Random $mathRandom
57
67
* @param string $connectionName
68
+ * @param StoreManagerInterface $storeManager
58
69
*/
59
70
public function __construct (
60
71
\Magento \Framework \Model \ResourceModel \Db \Context $ context ,
61
72
\Magento \Framework \Stdlib \DateTime \DateTime $ date ,
62
73
\Magento \Framework \Math \Random $ mathRandom ,
63
- $ connectionName = null
74
+ $ connectionName = null ,
75
+ StoreManagerInterface $ storeManager = null
64
76
) {
65
77
$ this ->_date = $ date ;
66
78
$ this ->mathRandom = $ mathRandom ;
79
+ $ this ->storeManager = $ storeManager ?: ObjectManager::getInstance ()
80
+ ->get (StoreManagerInterface::class);
67
81
parent ::__construct ($ context , $ connectionName );
68
82
}
69
83
@@ -118,6 +132,9 @@ public function loadByEmail($subscriberEmail)
118
132
*/
119
133
public function loadByCustomerData (\Magento \Customer \Api \Data \CustomerInterface $ customer )
120
134
{
135
+ $ storeId = (int )$ customer ->getStoreId () ?: $ this ->storeManager
136
+ ->getWebsite ($ customer ->getWebsiteId ())->getDefaultStore ()->getId ();
137
+
121
138
$ select = $ this ->connection
122
139
->select ()
123
140
->from ($ this ->getMainTable ())
@@ -128,7 +145,7 @@ public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface
128
145
$ select ,
129
146
[
130
147
'customer_id ' => $ customer ->getId (),
131
- 'store_id ' => $ customer -> getStoreId ()
148
+ 'store_id ' => $ storeId
132
149
]
133
150
);
134
151
@@ -146,7 +163,7 @@ public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface
146
163
$ select ,
147
164
[
148
165
'subscriber_email ' => $ customer ->getEmail (),
149
- 'store_id ' => $ customer -> getStoreId ()
166
+ 'store_id ' => $ storeId
150
167
]
151
168
);
152
169
0 commit comments