@@ -130,6 +130,8 @@ public function __construct(
130
130
}
131
131
132
132
/**
133
+ * Save.
134
+ *
133
135
* {@inheritdoc}
134
136
*/
135
137
public function save (\Magento \Customer \Api \Data \CustomerInterface $ customer , $ passwordHash = null )
@@ -175,19 +177,7 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
175
177
);
176
178
}
177
179
// Populate model with secure data
178
- if ($ customer ->getId ()) {
179
- $ customerSecure = $ this ->customerRegistry ->retrieveSecureData ($ customer ->getId ());
180
- $ customerModel ->setRpToken ($ customerSecure ->getRpToken ());
181
- $ customerModel ->setRpTokenCreatedAt ($ customerSecure ->getRpTokenCreatedAt ());
182
- $ customerModel ->setPasswordHash ($ customerSecure ->getPasswordHash ());
183
- $ customerModel ->setFailuresNum ($ customerSecure ->getFailuresNum ());
184
- $ customerModel ->setFirstFailure ($ customerSecure ->getFirstFailure ());
185
- $ customerModel ->setLockExpires ($ customerSecure ->getLockExpires ());
186
- } else {
187
- if ($ passwordHash ) {
188
- $ customerModel ->setPasswordHash ($ passwordHash );
189
- }
190
- }
180
+ $ this ->populateCustomerModelWithSecureData ($ customer , $ passwordHash , $ customerModel );
191
181
192
182
// If customer email was changed, reset RpToken info
193
183
if ($ prevCustomerData
@@ -197,19 +187,9 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
197
187
$ customerModel ->setRpTokenCreatedAt (null );
198
188
}
199
189
200
- if (!array_key_exists ('default_billing ' , $ customerArr ) &&
201
- null !== $ prevCustomerDataArr &&
202
- array_key_exists ('default_billing ' , $ prevCustomerDataArr )
203
- ) {
204
- $ customerModel ->setDefaultBilling ($ prevCustomerDataArr ['default_billing ' ]);
205
- }
190
+ $ this ->setDefaultBilling ($ customerArr , $ prevCustomerDataArr , $ customerModel );
206
191
207
- if (!array_key_exists ('default_shipping ' , $ customerArr ) &&
208
- null !== $ prevCustomerDataArr &&
209
- array_key_exists ('default_shipping ' , $ prevCustomerDataArr )
210
- ) {
211
- $ customerModel ->setDefaultShipping ($ prevCustomerDataArr ['default_shipping ' ]);
212
- }
192
+ $ this ->setDefaultShipping ($ customerArr , $ prevCustomerDataArr , $ customerModel );
213
193
214
194
$ customerModel ->save ();
215
195
$ this ->customerRegistry ->push ($ customerModel );
@@ -226,6 +206,8 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
226
206
}
227
207
228
208
/**
209
+ * Get.
210
+ *
229
211
* {@inheritdoc}
230
212
*/
231
213
public function get ($ email , $ websiteId = null )
@@ -235,6 +217,8 @@ public function get($email, $websiteId = null)
235
217
}
236
218
237
219
/**
220
+ * Get by Id.
221
+ *
238
222
* {@inheritdoc}
239
223
*/
240
224
public function getById ($ customerId )
@@ -244,6 +228,8 @@ public function getById($customerId)
244
228
}
245
229
246
230
/**
231
+ * Get list.
232
+ *
247
233
* {@inheritdoc}
248
234
*/
249
235
public function getList (SearchCriteriaInterface $ searchCriteria )
@@ -296,6 +282,8 @@ public function getList(SearchCriteriaInterface $searchCriteria)
296
282
}
297
283
298
284
/**
285
+ * Delete.
286
+ *
299
287
* {@inheritdoc}
300
288
*/
301
289
public function delete (\Magento \Customer \Api \Data \CustomerInterface $ customer )
@@ -304,6 +292,8 @@ public function delete(\Magento\Customer\Api\Data\CustomerInterface $customer)
304
292
}
305
293
306
294
/**
295
+ * Delete by Id.
296
+ *
307
297
* {@inheritdoc}
308
298
*/
309
299
public function deleteById ($ customerId )
@@ -373,4 +363,65 @@ private function updateAddresses(\Magento\Customer\Api\Data\CustomerInterface $c
373
363
}
374
364
}
375
365
}
366
+
367
+ /**
368
+ * Populate customer model with secure data.
369
+ *
370
+ * @param \Magento\Customer\Api\Data\CustomerInterface $customer
371
+ * @param $passwordHash
372
+ * @param $customerModel
373
+ */
374
+ private function populateCustomerModelWithSecureData (
375
+ \Magento \Customer \Api \Data \CustomerInterface $ customer ,
376
+ $ passwordHash ,
377
+ $ customerModel
378
+ ) {
379
+ if ($ customer ->getId ()) {
380
+ $ customerSecure = $ this ->customerRegistry ->retrieveSecureData ($ customer ->getId ());
381
+ $ customerModel ->setRpToken ($ customerSecure ->getRpToken ());
382
+ $ customerModel ->setRpTokenCreatedAt ($ customerSecure ->getRpTokenCreatedAt ());
383
+ $ customerModel ->setPasswordHash ($ customerSecure ->getPasswordHash ());
384
+ $ customerModel ->setFailuresNum ($ customerSecure ->getFailuresNum ());
385
+ $ customerModel ->setFirstFailure ($ customerSecure ->getFirstFailure ());
386
+ $ customerModel ->setLockExpires ($ customerSecure ->getLockExpires ());
387
+ } else {
388
+ if ($ passwordHash ) {
389
+ $ customerModel ->setPasswordHash ($ passwordHash );
390
+ }
391
+ }
392
+ }
393
+
394
+ /**
395
+ * Set default billing.
396
+ *
397
+ * @param $customerArr
398
+ * @param $prevCustomerDataArr
399
+ * @param $customerModel
400
+ */
401
+ private function setDefaultBilling ($ customerArr , $ prevCustomerDataArr , $ customerModel )
402
+ {
403
+ if (!array_key_exists ('default_billing ' , $ customerArr ) &&
404
+ null !== $ prevCustomerDataArr &&
405
+ array_key_exists ('default_billing ' , $ prevCustomerDataArr )
406
+ ) {
407
+ $ customerModel ->setDefaultBilling ($ prevCustomerDataArr ['default_billing ' ]);
408
+ }
409
+ }
410
+
411
+ /**
412
+ * Set default shipping.
413
+ *
414
+ * @param $customerArr
415
+ * @param $prevCustomerDataArr
416
+ * @param $customerModel
417
+ */
418
+ private function setDefaultShipping ($ customerArr , $ prevCustomerDataArr , $ customerModel )
419
+ {
420
+ if (!array_key_exists ('default_shipping ' , $ customerArr ) &&
421
+ null !== $ prevCustomerDataArr &&
422
+ array_key_exists ('default_shipping ' , $ prevCustomerDataArr )
423
+ ) {
424
+ $ customerModel ->setDefaultShipping ($ prevCustomerDataArr ['default_shipping ' ]);
425
+ }
426
+ }
376
427
}
0 commit comments