3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Customer \Controller \Adminhtml \Index ;
7
8
8
9
use Magento \Backend \App \Action \Context ;
40
41
use Magento \Framework \Math \Random ;
41
42
use Magento \Framework \Reflection \DataObjectProcessor ;
42
43
use Magento \Framework \Registry ;
44
+ use Magento \Framework \Validator \Exception ;
43
45
use Magento \Framework \View \Result \LayoutFactory ;
44
46
use Magento \Framework \View \Result \PageFactory ;
45
47
use Magento \Newsletter \Model \SubscriberFactory ;
@@ -243,10 +245,10 @@ protected function _extractData(
243
245
/**
244
246
* Saves default_billing and default_shipping flags for customer address
245
247
*
246
- * @deprecated 102.0.1 must be removed because addresses are save separately for now
247
248
* @param array $addressIdList
248
249
* @param array $extractedCustomerData
249
250
* @return array
251
+ * @deprecated 102.0.1 must be removed because addresses are save separately for now
250
252
*/
251
253
protected function saveDefaultFlags (array $ addressIdList , array &$ extractedCustomerData )
252
254
{
@@ -286,9 +288,9 @@ protected function saveDefaultFlags(array $addressIdList, array &$extractedCusto
286
288
/**
287
289
* Reformat customer addresses data to be compatible with customer service interface
288
290
*
289
- * @deprecated 102.0.1 addresses are saved separately for now
290
291
* @param array $extractedCustomerData
291
292
* @return array
293
+ * @deprecated 102.0.1 addresses are saved separately for now
292
294
*/
293
295
protected function _extractCustomerAddressData (array &$ extractedCustomerData )
294
296
{
@@ -318,6 +320,7 @@ public function execute()
318
320
{
319
321
$ returnToEdit = false ;
320
322
$ customerId = $ this ->getCurrentCustomerId ();
323
+ $ customer = $ this ->customerDataFactory ->create ();
321
324
322
325
if ($ this ->getRequest ()->getPostValue ()) {
323
326
try {
@@ -335,8 +338,6 @@ public function execute()
335
338
$ customerData ['id ' ] = $ customerId ;
336
339
}
337
340
338
- /** @var CustomerInterface $customer */
339
- $ customer = $ this ->customerDataFactory ->create ();
340
341
$ this ->dataObjectHelper ->populateWithArray (
341
342
$ customer ,
342
343
$ customerData ,
@@ -353,15 +354,14 @@ public function execute()
353
354
try {
354
355
$ this ->customerAccountManagement ->validateCustomerStoreIdByWebsiteId ($ customer );
355
356
} catch (LocalizedException $ exception ) {
356
- throw new LocalizedException (__ ("The Store View selected for sending Welcome email from " .
357
+ throw new LocalizedException (__ ("The Store View selected for sending Welcome email from " .
357
358
" is not related to the customer's associated website. " ));
358
359
}
359
360
}
360
361
361
362
// Save customer
362
363
if ($ customerId ) {
363
364
$ this ->_customerRepository ->save ($ customer );
364
-
365
365
$ this ->getEmailNotification ()->credentialsChanged ($ customer , $ currentCustomer ->getEmail ());
366
366
} else {
367
367
$ customer = $ this ->customerAccountManagement ->createAccount ($ customer );
@@ -386,13 +386,13 @@ public function execute()
386
386
__ ('Something went wrong while saving the customer. ' )
387
387
);
388
388
$ returnToEdit = false ;
389
- } catch (\ Magento \ Framework \ Validator \ Exception $ exception ) {
389
+ } catch (Exception $ exception ) {
390
390
$ messages = $ exception ->getMessages ();
391
391
if (empty ($ messages )) {
392
392
$ messages = $ exception ->getMessage ();
393
393
}
394
394
$ this ->_addSessionErrorMessages ($ messages );
395
- $ this ->_getSession ()->setCustomerFormData ($ this ->retrieveFormattedFormData ());
395
+ $ this ->_getSession ()->setCustomerFormData ($ this ->retrieveFormattedFormData ($ customer ));
396
396
$ returnToEdit = true ;
397
397
} catch (AbstractAggregateException $ exception ) {
398
398
$ errors = $ exception ->getErrors ();
@@ -401,18 +401,18 @@ public function execute()
401
401
$ messages [] = $ error ->getMessage ();
402
402
}
403
403
$ this ->_addSessionErrorMessages ($ messages );
404
- $ this ->_getSession ()->setCustomerFormData ($ this ->retrieveFormattedFormData ());
404
+ $ this ->_getSession ()->setCustomerFormData ($ this ->retrieveFormattedFormData ($ customer ));
405
405
$ returnToEdit = true ;
406
406
} catch (LocalizedException $ exception ) {
407
407
$ this ->_addSessionErrorMessages ($ exception ->getMessage ());
408
- $ this ->_getSession ()->setCustomerFormData ($ this ->retrieveFormattedFormData ());
408
+ $ this ->_getSession ()->setCustomerFormData ($ this ->retrieveFormattedFormData ($ customer ));
409
409
$ returnToEdit = true ;
410
410
} catch (\Exception $ exception ) {
411
411
$ this ->messageManager ->addExceptionMessage (
412
412
$ exception ,
413
413
__ ('Something went wrong while saving the customer. ' )
414
414
);
415
- $ this ->_getSession ()->setCustomerFormData ($ this ->retrieveFormattedFormData ());
415
+ $ this ->_getSession ()->setCustomerFormData ($ this ->retrieveFormattedFormData ($ customer ));
416
416
$ returnToEdit = true ;
417
417
}
418
418
}
@@ -553,21 +553,16 @@ private function disableAddressValidation($customer)
553
553
/**
554
554
* Retrieve formatted form data
555
555
*
556
+ * @param CustomerInterface $customer
556
557
* @return array
557
558
*/
558
- private function retrieveFormattedFormData (): array
559
+ private function retrieveFormattedFormData (CustomerInterface $ customer ): array
559
560
{
560
561
$ originalRequestData = $ this ->getRequest ()->getPostValue ();
562
+ $ customerData = $ this ->customerMapper ->toFlatArray ($ customer );
561
563
562
564
/* Customer data filtration */
563
565
if (isset ($ originalRequestData ['customer ' ])) {
564
- $ customerData = $ this ->_extractData (
565
- 'adminhtml_customer ' ,
566
- CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER ,
567
- [],
568
- 'customer '
569
- );
570
-
571
566
$ customerData = array_intersect_key ($ customerData , $ originalRequestData ['customer ' ]);
572
567
$ originalRequestData ['customer ' ] = array_merge ($ originalRequestData ['customer ' ], $ customerData );
573
568
}
0 commit comments