Skip to content

Commit d09e3b7

Browse files
committed
GraphQL-409: address_type is null after setting billing and shipping addresses on cart
1 parent b3d1c48 commit d09e3b7

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/ExtractDataFromAddress.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10+
use Magento\Customer\Model\Address\AbstractAddress;
1011
use Magento\Framework\Api\ExtensibleDataObjectConverter;
1112
use Magento\Quote\Api\Data\AddressInterface;
1213
use Magento\Quote\Model\Quote\Address as QuoteAddress;
@@ -40,9 +41,17 @@ public function execute(QuoteAddress $address): array
4041
$addressData = $this->dataObjectConverter->toFlatArray($address, [], AddressInterface::class);
4142
$addressData['model'] = $address;
4243

44+
if ($address->getAddressType() == AbstractAddress::TYPE_SHIPPING) {
45+
$addressType = 'SHIPPING';
46+
} elseif ($address->getAddressType() == AbstractAddress::TYPE_BILLING) {
47+
$addressType = 'BILLING';
48+
} else {
49+
$addressType = null;
50+
}
51+
4352
$addressData = array_merge($addressData, [
4453
'address_id' => $address->getId(),
45-
'address_type' => $address->getAddressType(),
54+
'address_type' => $addressType,
4655
'country' => [
4756
'code' => $address->getCountryId(),
4857
'label' => $address->getCountry()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function testSetNewBillingAddressWithUseForShippingParameter()
177177
self::assertArrayHasKey('shipping_addresses', $cartResponse);
178178
$shippingAddressResponse = current($cartResponse['shipping_addresses']);
179179
$this->assertNewAddressFields($billingAddressResponse);
180-
$this->assertNewAddressFields($shippingAddressResponse, 'shipping');
180+
$this->assertNewAddressFields($shippingAddressResponse, 'SHIPPING');
181181
}
182182

183183
/**
@@ -409,7 +409,7 @@ public function testSetBillingAddressIfCustomerIsNotOwnerOfAddress()
409409
* @param array $addressResponse
410410
* @param string $addressType
411411
*/
412-
private function assertNewAddressFields(array $addressResponse, string $addressType = 'billing'): void
412+
private function assertNewAddressFields(array $addressResponse, string $addressType = 'BILLING'): void
413413
{
414414
$assertionMap = [
415415
['response_field' => 'firstname', 'expected_value' => 'test firstname'],

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function testSetNewBillingAddressWithUseForShippingParameter()
168168
self::assertArrayHasKey('shipping_addresses', $cartResponse);
169169
$shippingAddressResponse = current($cartResponse['shipping_addresses']);
170170
$this->assertNewAddressFields($billingAddressResponse);
171-
$this->assertNewAddressFields($shippingAddressResponse, 'shipping');
171+
$this->assertNewAddressFields($shippingAddressResponse, 'SHIPPING');
172172
}
173173

174174
/**
@@ -250,7 +250,7 @@ public function testSetBillingAddressFromAddressBook()
250250
* @param array $addressResponse
251251
* @param string $addressType
252252
*/
253-
private function assertNewAddressFields(array $addressResponse, string $addressType = 'billing'): void
253+
private function assertNewAddressFields(array $addressResponse, string $addressType = 'BILLING'): void
254254
{
255255
$assertionMap = [
256256
['response_field' => 'firstname', 'expected_value' => 'test firstname'],

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingAddressOnCartTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ private function assertNewShippingAddressFields(array $shippingAddressResponse):
474474
['response_field' => 'postcode', 'expected_value' => '887766'],
475475
['response_field' => 'telephone', 'expected_value' => '88776655'],
476476
['response_field' => 'country', 'expected_value' => ['code' => 'US', 'label' => 'US']],
477-
['response_field' => 'address_type', 'expected_value' => 'shipping']
477+
['response_field' => 'address_type', 'expected_value' => 'SHIPPING']
478478
];
479479

480480
$this->assertResponseFields($shippingAddressResponse, $assertionMap);

0 commit comments

Comments
 (0)