Skip to content

Commit c5b3429

Browse files
pmclainnaydav
authored andcommitted
Fix region_id update in updateCustomerAddress mutation
This commit maps `region/region_id` to `AddressInterface:regionId` when provided as input. The `AddressInterface` contains both `region` and `regionId` properties which are mapped to `\Magento\Customer\Model\Address` by the `AddressRepositoryInterface`. After populating an existing customer address with the user input for `region`, the exting `regionId` was still set on the `AddressInterface`. When saving the `region` property is mapped to the model before `regionId`. https://github.com/magento/magento2/blob/1a92f1c1609445c7b6b107a165d387e306f2f779/app/code/Magento/Customer/Model/Address.php#L141-L167
1 parent 1f77329 commit c5b3429

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

app/code/Magento/CustomerGraphQl/Model/Resolver/UpdateCustomerAddress.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ private function updateCustomerAddress(int $customerId, int $addressId, array $a
109109
{
110110
$address = $this->getCustomerAddressForUser->execute($addressId, $customerId);
111111
$this->dataObjectHelper->populateWithArray($address, $addressData, AddressInterface::class);
112+
if (isset($addressData['region']['region_id'])) {
113+
$address->setRegionId($address->getRegion()->getRegionId());
114+
}
115+
112116
return $this->addressRepository->save($address);
113117
}
114118
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/UpdateCustomerAddressTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,12 @@ private function assertCustomerAddressesFields(AddressInterface $address, $actua
218218
];
219219
$this->assertResponseFields($actualResponse, $assertionMap);
220220
$this->assertTrue(is_array([$actualResponse['region']]), "region field must be of an array type.");
221-
// https://github.com/magento/graphql-ce/issues/270
222-
// $assertionRegionMap = [
223-
// ['response_field' => 'region', 'expected_value' => $address->getRegion()->getRegion()],
224-
// ['response_field' => 'region_code', 'expected_value' => $address->getRegion()->getRegionCode()],
225-
// ['response_field' => 'region_id', 'expected_value' => $address->getRegion()->getRegionId()]
226-
// ];
227-
// $this->assertResponseFields($actualResponse['region'], $assertionRegionMap);
221+
$assertionRegionMap = [
222+
['response_field' => 'region', 'expected_value' => $address->getRegion()->getRegion()],
223+
['response_field' => 'region_code', 'expected_value' => $address->getRegion()->getRegionCode()],
224+
['response_field' => 'region_id', 'expected_value' => $address->getRegion()->getRegionId()]
225+
];
226+
$this->assertResponseFields($actualResponse['region'], $assertionRegionMap);
228227
}
229228

230229
/**

0 commit comments

Comments
 (0)