Skip to content

Commit c59f7bb

Browse files
Deepak TiwariDeepak Tiwari
authored andcommitted
AC-13512 - admin customer module improvements
1 parent 6de22d4 commit c59f7bb

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ protected function _extractCustomerData()
190190
$customerData = [];
191191
if ($this->getRequest()->getPost('customer')) {
192192
$additionalAttributes = [
193-
CustomerInterface::DEFAULT_BILLING,
194-
CustomerInterface::DEFAULT_SHIPPING,
195193
'confirmation',
196194
'sendemail_store_id',
197195
'extension_attributes',

app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,17 @@ public function save(CustomerInterface $customer, $passwordHash = null)
206206
/** @var NewOperation|null $delegatedNewOperation */
207207
$delegatedNewOperation = !$customer->getId() ? $this->delegatedStorage->consumeNewOperation() : null;
208208
$prevCustomerData = $prevCustomerDataArr = null;
209-
if ($customer->getDefaultBilling()) {
210-
$this->validateDefaultAddress($customer, CustomerInterface::DEFAULT_BILLING);
211-
}
212-
if ($customer->getDefaultShipping()) {
213-
$this->validateDefaultAddress($customer, CustomerInterface::DEFAULT_SHIPPING);
214-
}
215209
if ($customer->getId()) {
216210
$prevCustomerData = $this->getById($customer->getId());
217211
$prevCustomerDataArr = $this->prepareCustomerData($prevCustomerData->__toArray());
218212
$customer->setCreatedAt($prevCustomerData->getCreatedAt());
219213
}
214+
if ($customer->getDefaultBilling()) {
215+
$this->validateDefaultAddress($customer, $prevCustomerData, CustomerInterface::DEFAULT_BILLING);
216+
}
217+
if ($customer->getDefaultShipping()) {
218+
$this->validateDefaultAddress($customer, $prevCustomerData, CustomerInterface::DEFAULT_SHIPPING);
219+
}
220220
/** @var $customer \Magento\Customer\Model\Data\Customer */
221221
$customerArr = $customer->__toArray();
222222
$customer = $this->imageProcessor->save(
@@ -569,28 +569,24 @@ private function prepareCustomerData(array $customerData): array
569569
* To validate default address
570570
*
571571
* @param CustomerInterface $customer
572+
* @param CustomerInterface|null $prevCustomerData
572573
* @param string $defaultAddressType
573574
* @return void
574575
* @throws InputException
575576
*/
576577
private function validateDefaultAddress(
577578
CustomerInterface $customer,
579+
?CustomerInterface $prevCustomerData,
578580
string $defaultAddressType
579581
): void {
580582
$defaultAddressId = $defaultAddressType === CustomerInterface::DEFAULT_BILLING ?
581583
(int) $customer->getDefaultBilling() : (int) $customer->getDefaultShipping();
582-
583-
if ($customer->getAddresses()) {
584-
foreach ($customer->getAddresses() as $address) {
585-
$addressArray = $address->__toArray();
586-
$addressId = (int) $address->getId();
587-
if (!empty($addressArray[$defaultAddressType])
588-
|| empty($addressId)
589-
|| $defaultAddressId === $addressId) {
584+
if ($prevCustomerData && $prevCustomerData->getAddresses()) {
585+
foreach ($prevCustomerData->getAddresses() as $address) {
586+
if ($defaultAddressId === (int) $address->getId()) {
590587
return;
591588
}
592589
}
593-
594590
throw new InputException(
595591
__(
596592
'The %fieldName value is invalid. Set the correct value and try again.',

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/SaveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public function testExistingCustomerChangeEmail(): void
385385
'sendemail_store_id' => '1',
386386
'sendemail' => '1',
387387
CustomerData::CREATED_AT => '2000-01-01 00:00:00',
388-
CustomerData::DEFAULT_SHIPPING => '_item1',
388+
CustomerData::DEFAULT_SHIPPING => '1',
389389
CustomerData::DEFAULT_BILLING => '1'
390390
]
391391
];

0 commit comments

Comments
 (0)