Skip to content

Commit 993a006

Browse files
committed
Merge remote-tracking branch 'origin/imported-magento-magento2-30963' into 2.4-develop-pr112
2 parents b89fc2f + 5ae05e0 commit 993a006

File tree

6 files changed

+163
-117
lines changed

6 files changed

+163
-117
lines changed

app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Customer\Controller\Adminhtml\Index;
78

89
use Magento\Backend\App\Action\Context;
@@ -40,6 +41,7 @@
4041
use Magento\Framework\Math\Random;
4142
use Magento\Framework\Reflection\DataObjectProcessor;
4243
use Magento\Framework\Registry;
44+
use Magento\Framework\Validator\Exception;
4345
use Magento\Framework\View\Result\LayoutFactory;
4446
use Magento\Framework\View\Result\PageFactory;
4547
use Magento\Newsletter\Model\SubscriberFactory;
@@ -243,10 +245,10 @@ protected function _extractData(
243245
/**
244246
* Saves default_billing and default_shipping flags for customer address
245247
*
246-
* @deprecated 102.0.1 must be removed because addresses are save separately for now
247248
* @param array $addressIdList
248249
* @param array $extractedCustomerData
249250
* @return array
251+
* @deprecated 102.0.1 must be removed because addresses are save separately for now
250252
*/
251253
protected function saveDefaultFlags(array $addressIdList, array &$extractedCustomerData)
252254
{
@@ -286,9 +288,9 @@ protected function saveDefaultFlags(array $addressIdList, array &$extractedCusto
286288
/**
287289
* Reformat customer addresses data to be compatible with customer service interface
288290
*
289-
* @deprecated 102.0.1 addresses are saved separately for now
290291
* @param array $extractedCustomerData
291292
* @return array
293+
* @deprecated 102.0.1 addresses are saved separately for now
292294
*/
293295
protected function _extractCustomerAddressData(array &$extractedCustomerData)
294296
{
@@ -318,6 +320,7 @@ public function execute()
318320
{
319321
$returnToEdit = false;
320322
$customerId = $this->getCurrentCustomerId();
323+
$customer = $this->customerDataFactory->create();
321324

322325
if ($this->getRequest()->getPostValue()) {
323326
try {
@@ -335,8 +338,6 @@ public function execute()
335338
$customerData['id'] = $customerId;
336339
}
337340

338-
/** @var CustomerInterface $customer */
339-
$customer = $this->customerDataFactory->create();
340341
$this->dataObjectHelper->populateWithArray(
341342
$customer,
342343
$customerData,
@@ -353,15 +354,14 @@ public function execute()
353354
try {
354355
$this->customerAccountManagement->validateCustomerStoreIdByWebsiteId($customer);
355356
} 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" .
357358
" is not related to the customer's associated website."));
358359
}
359360
}
360361

361362
// Save customer
362363
if ($customerId) {
363364
$this->_customerRepository->save($customer);
364-
365365
$this->getEmailNotification()->credentialsChanged($customer, $currentCustomer->getEmail());
366366
} else {
367367
$customer = $this->customerAccountManagement->createAccount($customer);
@@ -386,13 +386,13 @@ public function execute()
386386
__('Something went wrong while saving the customer.')
387387
);
388388
$returnToEdit = false;
389-
} catch (\Magento\Framework\Validator\Exception $exception) {
389+
} catch (Exception $exception) {
390390
$messages = $exception->getMessages();
391391
if (empty($messages)) {
392392
$messages = $exception->getMessage();
393393
}
394394
$this->_addSessionErrorMessages($messages);
395-
$this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData());
395+
$this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData($customer));
396396
$returnToEdit = true;
397397
} catch (AbstractAggregateException $exception) {
398398
$errors = $exception->getErrors();
@@ -401,18 +401,18 @@ public function execute()
401401
$messages[] = $error->getMessage();
402402
}
403403
$this->_addSessionErrorMessages($messages);
404-
$this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData());
404+
$this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData($customer));
405405
$returnToEdit = true;
406406
} catch (LocalizedException $exception) {
407407
$this->_addSessionErrorMessages($exception->getMessage());
408-
$this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData());
408+
$this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData($customer));
409409
$returnToEdit = true;
410410
} catch (\Exception $exception) {
411411
$this->messageManager->addExceptionMessage(
412412
$exception,
413413
__('Something went wrong while saving the customer.')
414414
);
415-
$this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData());
415+
$this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData($customer));
416416
$returnToEdit = true;
417417
}
418418
}
@@ -553,21 +553,16 @@ private function disableAddressValidation($customer)
553553
/**
554554
* Retrieve formatted form data
555555
*
556+
* @param CustomerInterface $customer
556557
* @return array
557558
*/
558-
private function retrieveFormattedFormData(): array
559+
private function retrieveFormattedFormData(CustomerInterface $customer): array
559560
{
560561
$originalRequestData = $this->getRequest()->getPostValue();
562+
$customerData = $this->customerMapper->toFlatArray($customer);
561563

562564
/* Customer data filtration */
563565
if (isset($originalRequestData['customer'])) {
564-
$customerData = $this->_extractData(
565-
'adminhtml_customer',
566-
CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER,
567-
[],
568-
'customer'
569-
);
570-
571566
$customerData = array_intersect_key($customerData, $originalRequestData['customer']);
572567
$originalRequestData['customer'] = array_merge($originalRequestData['customer'], $customerData);
573568
}

app/code/Magento/Customer/Model/Customer/DataProviderWithDefaultAddresses.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
use Magento\Customer\Model\Address;
1010
use Magento\Customer\Model\Customer;
11+
use Magento\Customer\Model\CustomerFactory;
1112
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
1213
use Magento\Directory\Model\CountryFactory;
1314
use Magento\Eav\Model\Config;
1415
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1516
use Magento\Eav\Model\Entity\Type;
17+
use Magento\Framework\App\ObjectManager;
1618
use Magento\Framework\Exception\LocalizedException;
1719
use Magento\Framework\Session\SessionManagerInterface;
1820
use Magento\Customer\Model\FileUploaderDataResolver;
@@ -66,6 +68,11 @@ class DataProviderWithDefaultAddresses extends AbstractDataProvider
6668
*/
6769
private $attributeMetadataResolver;
6870

71+
/**
72+
* @var CustomerFactory
73+
*/
74+
private $customerFactory;
75+
6976
/**
7077
* @param string $name
7178
* @param string $primaryFieldName
@@ -79,6 +86,7 @@ class DataProviderWithDefaultAddresses extends AbstractDataProvider
7986
* @param bool $allowToShowHiddenAttributes
8087
* @param array $meta
8188
* @param array $data
89+
* @param CustomerFactory $customerFactory
8290
* @throws LocalizedException
8391
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8492
*/
@@ -94,7 +102,8 @@ public function __construct(
94102
AttributeMetadataResolver $attributeMetadataResolver,
95103
$allowToShowHiddenAttributes = true,
96104
array $meta = [],
97-
array $data = []
105+
array $data = [],
106+
CustomerFactory $customerFactory = null
98107
) {
99108
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
100109
$this->collection = $customerCollectionFactory->create();
@@ -107,6 +116,7 @@ public function __construct(
107116
$this->meta['customer']['children'] = $this->getAttributesMeta(
108117
$eavConfig->getEntityType('customer')
109118
);
119+
$this->customerFactory = $customerFactory ?: ObjectManager::getInstance()->get(CustomerFactory::class);
110120
}
111121

112122
/**
@@ -142,9 +152,10 @@ public function getData(): array
142152

143153
$this->loadedData[$customer->getId()] = $result;
144154
}
145-
146155
$data = $this->session->getCustomerFormData();
147156
if (!empty($data)) {
157+
$customer = $this->customerFactory->create();
158+
$this->fileUploaderDataResolver->overrideFileUploaderData($customer, $data['customer']);
148159
$customerId = $data['customer']['entity_id'] ?? null;
149160
$this->loadedData[$customerId] = $data;
150161
$this->session->unsCustomerFormData();

0 commit comments

Comments
 (0)