5
5
*/
6
6
namespace Magento \CustomerImportExport \Model \ResourceModel \Import \Customer ;
7
7
8
- use Magento \Customer \Api \CustomerRepositoryInterface ;
8
+ use Magento \Customer \Model \Config \Share ;
9
+ use Magento \Framework \App \ObjectManager ;
9
10
use Magento \Customer \Model \ResourceModel \Customer \Collection as CustomerCollection ;
10
11
use Magento \Customer \Model \ResourceModel \Customer \CollectionFactory as CustomerCollectionFactory ;
11
12
use Magento \Framework \DataObject ;
@@ -30,11 +31,6 @@ class Storage
30
31
*/
31
32
protected $ _customerIds = [];
32
33
33
- /**
34
- * @var array
35
- */
36
- private $ customerIdsByEmail = [];
37
-
38
34
/**
39
35
* Number of items to fetch from db in one query
40
36
*
@@ -67,26 +63,26 @@ class Storage
67
63
private $ customerStoreIds = [];
68
64
69
65
/**
70
- * @var CustomerRepositoryInterface
66
+ * @var Share
71
67
*/
72
- private $ customerRepository ;
68
+ private $ configShare ;
73
69
74
70
/**
75
71
* @param CustomerCollectionFactory $collectionFactory
76
- * @param CustomerRepositoryInterface $customerRepository
77
72
* @param array $data
73
+ * @param Share|null $configShare
78
74
*/
79
75
public function __construct (
80
76
CustomerCollectionFactory $ collectionFactory ,
81
- CustomerRepositoryInterface $ customerRepository ,
82
- array $ data = []
77
+ array $ data = [] ,
78
+ ? Share $ configShare = null
83
79
) {
84
80
$ this ->_customerCollection = isset (
85
81
$ data ['customer_collection ' ]
86
82
) ? $ data ['customer_collection ' ] : $ collectionFactory ->create ();
87
83
$ this ->_pageSize = isset ($ data ['page_size ' ]) ? (int ) $ data ['page_size ' ] : 0 ;
88
84
$ this ->customerCollectionFactory = $ collectionFactory ;
89
- $ this ->customerRepository = $ customerRepository ;
85
+ $ this ->configShare = $ configShare ?? ObjectManager:: getInstance ()-> get (Share::class) ;
90
86
}
91
87
92
88
/**
@@ -134,9 +130,14 @@ public function addCustomerByArray(array $customer): Storage
134
130
if (!isset ($ this ->customerStoreIds [$ email ])) {
135
131
$ this ->customerStoreIds [$ email ] = [];
136
132
}
137
- $ websiteId = (int ) $ customer ['website_id ' ];
138
- $ this ->_customerIds [$ email ][$ websiteId ] = (int ) $ customer ['entity_id ' ];
139
- $ this ->customerStoreIds [$ email ][$ websiteId ] = $ customer ['store_id ' ] ?? null ;
133
+ if ($ this ->configShare ->isGlobalScope ()) {
134
+ $ this ->_customerIds [$ email ] = (int ) $ customer ['entity_id ' ];
135
+ $ this ->customerStoreIds [$ email ]= $ customer ['store_id ' ] ?? null ;
136
+ } else {
137
+ $ websiteId = (int ) $ customer ['website_id ' ];
138
+ $ this ->_customerIds [$ email ][$ websiteId ] = (int ) $ customer ['entity_id ' ];
139
+ $ this ->customerStoreIds [$ email ][$ websiteId ] = $ customer ['store_id ' ] ?? null ;
140
+ }
140
141
141
142
return $ this ;
142
143
}
@@ -172,30 +173,15 @@ public function getCustomerId(string $email, int $websiteId)
172
173
$ email = mb_strtolower ($ email );
173
174
$ this ->loadCustomerData ($ email , $ websiteId );
174
175
175
- if (isset ($ this ->_customerIds [$ email][ $ websiteId ])) {
176
- return $ this ->_customerIds [$ email ][ $ websiteId ] ;
176
+ if ($ this -> configShare -> isGlobalScope () && isset ($ this ->_customerIds [$ email ])) {
177
+ return $ this ->_customerIds [$ email ];
177
178
}
178
179
179
- return false ;
180
- }
181
-
182
- /**
183
- * Find customer ID by email.
184
- *
185
- * @param string $email
186
- * @return bool|int
187
- */
188
- public function getCustomerIdByEmail (string $ email )
189
- {
190
- if (!isset ($ this ->customerIdsByEmail [$ email ])) {
191
- try {
192
- $ this ->customerIdsByEmail [$ email ] = $ this ->customerRepository ->get ($ email )->getId ();
193
- } catch (\Magento \Framework \Exception \NoSuchEntityException $ e ) {
194
- $ this ->customerIdsByEmail [$ email ] = false ;
195
- }
180
+ if (!$ this ->configShare ->isGlobalScope () && isset ($ this ->_customerIds [$ email ][$ websiteId ])) {
181
+ return $ this ->_customerIds [$ email ][$ websiteId ];
196
182
}
197
183
198
- return $ this -> customerIdsByEmail [ $ email ] ;
184
+ return false ;
199
185
}
200
186
201
187
/**
@@ -254,8 +240,13 @@ public function prepareCustomers(array $customersToFind): void
254
240
$ this ->_customerIds [$ email ] = [];
255
241
$ this ->customerStoreIds [$ email ] = [];
256
242
}
257
- $ this ->_customerIds [$ email ][$ websiteId ] = null ;
258
- $ this ->customerStoreIds [$ email ][$ websiteId ] = null ;
243
+ if ($ this ->configShare ->isGlobalScope ()) {
244
+ $ this ->_customerIds [$ email ] = null ;
245
+ $ this ->customerStoreIds [$ email ] = null ;
246
+ } else {
247
+ $ this ->_customerIds [$ email ][$ websiteId ] = null ;
248
+ $ this ->customerStoreIds [$ email ][$ websiteId ] = null ;
249
+ }
259
250
}
260
251
}
261
252
if (!$ identifiers ) {
@@ -289,7 +280,11 @@ private function loadCustomerData(string $email, int $websiteId): void
289
280
*/
290
281
private function isLoadedCustomerData (string $ email , int $ websiteId ): bool
291
282
{
292
- return array_key_exists ($ email , $ this ->_customerIds )
293
- && array_key_exists ($ websiteId , $ this ->_customerIds [$ email ]);
283
+ if ($ this ->configShare ->isGlobalScope ()) {
284
+ return array_key_exists ($ email , $ this ->_customerIds );
285
+ } else {
286
+ return array_key_exists ($ email , $ this ->_customerIds )
287
+ && array_key_exists ($ websiteId , $ this ->_customerIds [$ email ]);
288
+ }
294
289
}
295
290
}
0 commit comments