Skip to content

Commit 617fdd1

Browse files
ENGCOM-5699: Correct cart_item_id source for address items #853
- Merge Pull Request magento/graphql-ce#853 from pmclain/graphql-ce:issue/822 - Merged commits: 1. f0bb8d5 2. b2a21ed 3. 16e8358 4. 9d54005
2 parents 4321600 + 9d54005 commit 617fdd1

File tree

2 files changed

+63
-33
lines changed

2 files changed

+63
-33
lines changed

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10-
use Magento\Customer\Model\Address\AbstractAddress;
1110
use Magento\Framework\Api\ExtensibleDataObjectConverter;
1211
use Magento\Quote\Api\Data\AddressInterface;
1312
use Magento\Quote\Model\Quote\Address as QuoteAddress;
@@ -41,28 +40,37 @@ public function execute(QuoteAddress $address): array
4140
$addressData = $this->dataObjectConverter->toFlatArray($address, [], AddressInterface::class);
4241
$addressData['model'] = $address;
4342

44-
$addressData = array_merge($addressData, [
45-
'country' => [
46-
'code' => $address->getCountryId(),
47-
'label' => $address->getCountry()
48-
],
49-
'region' => [
50-
'code' => $address->getRegionCode(),
51-
'label' => $address->getRegion()
52-
],
53-
'street' => $address->getStreet(),
54-
'items_weight' => $address->getWeight(),
55-
'customer_notes' => $address->getCustomerNotes()
56-
]);
43+
$addressData = array_merge(
44+
$addressData,
45+
[
46+
'country' => [
47+
'code' => $address->getCountryId(),
48+
'label' => $address->getCountry()
49+
],
50+
'region' => [
51+
'code' => $address->getRegionCode(),
52+
'label' => $address->getRegion()
53+
],
54+
'street' => $address->getStreet(),
55+
'items_weight' => $address->getWeight(),
56+
'customer_notes' => $address->getCustomerNotes()
57+
]
58+
);
5759

5860
if (!$address->hasItems()) {
5961
return $addressData;
6062
}
6163

6264
$addressItemsData = [];
6365
foreach ($address->getAllItems() as $addressItem) {
66+
if ($addressItem instanceof \Magento\Quote\Model\Quote\Item) {
67+
$itemId = $addressItem->getItemId();
68+
} else {
69+
$itemId = $addressItem->getQuoteItemId();
70+
}
71+
6472
$addressItemsData[] = [
65-
'cart_item_id' => $addressItem->getQuoteItemId(),
73+
'cart_item_id' => $itemId,
6674
'quantity' => $addressItem->getQty()
6775
];
6876
}

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

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function testGetAvailableShippingMethods()
6767
'value' => 10,
6868
'currency' => 'USD',
6969
],
70+
'base_amount' => null,
7071
];
7172
self::assertEquals(
7273
$expectedAddressData,
@@ -135,25 +136,46 @@ private function getQuery(string $maskedQuoteId): string
135136
query {
136137
cart (cart_id: "{$maskedQuoteId}") {
137138
shipping_addresses {
138-
available_shipping_methods {
139-
amount {
140-
value
141-
currency
142-
}
143-
carrier_code
144-
carrier_title
145-
error_message
146-
method_code
147-
method_title
148-
price_excl_tax {
149-
value
150-
currency
151-
}
152-
price_incl_tax {
153-
value
154-
currency
155-
}
139+
cart_items {
140+
cart_item_id
141+
quantity
142+
}
143+
available_shipping_methods {
144+
amount {
145+
value
146+
currency
156147
}
148+
carrier_code
149+
carrier_title
150+
error_message
151+
method_code
152+
method_title
153+
price_excl_tax {
154+
value
155+
currency
156+
}
157+
price_incl_tax {
158+
value
159+
currency
160+
}
161+
base_amount {
162+
value
163+
currency
164+
}
165+
carrier_code
166+
carrier_title
167+
error_message
168+
method_code
169+
method_title
170+
price_excl_tax {
171+
value
172+
currency
173+
}
174+
price_incl_tax {
175+
value
176+
currency
177+
}
178+
}
157179
}
158180
}
159181
}

0 commit comments

Comments
 (0)