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
@@ -117,6 +131,9 @@ public function loadByEmail($subscriberEmail)
117
131
*/
118
132
public function loadByCustomerData (\Magento \Customer \Api \Data \CustomerInterface $ customer )
119
133
{
134
+ $ storeId = (int )$ customer ->getStoreId () ?: $ this ->storeManager
135
+ ->getWebsite ($ customer ->getWebsiteId ())->getDefaultStore ()->getId ();
136
+
120
137
$ select = $ this ->connection
121
138
->select ()
122
139
->from ($ this ->getMainTable ())
@@ -127,7 +144,7 @@ public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface
127
144
$ select ,
128
145
[
129
146
'customer_id ' => $ customer ->getId (),
130
- 'store_id ' => $ customer -> getStoreId ()
147
+ 'store_id ' => $ storeId
131
148
]
132
149
);
133
150
@@ -145,7 +162,7 @@ public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface
145
162
$ select ,
146
163
[
147
164
'subscriber_email ' => $ customer ->getEmail (),
148
- 'store_id ' => $ customer -> getStoreId ()
165
+ 'store_id ' => $ storeId
149
166
]
150
167
);
151
168
0 commit comments