Skip to content

Commit f0bb8d5

Browse files
committed
Correct cart_item_id source for address items
[`\Magento\Quote\Model\Quote\Address::getAllItems`](https://github.com/magento/magento2/blob/cf4dc427fed594f74b7168735ee1eb93febfc143/app/code/Magento/Quote/Model/Quote/Address.php#L592-L636) returns `\Magento\Quote\Model\Quote\Address\Item[]` when the quote has multiple shipping addresses and `Magento\Quote\Model\Quote\Item[]` with a single shipping address. These objects have different methods for accessing the quote item id and both variants need to be accommodated in the extractor. Fixes magento/graphql-ce#822
1 parent e56640c commit f0bb8d5

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@ public function execute(QuoteAddress $address): array
6161

6262
$addressItemsData = [];
6363
foreach ($address->getAllItems() as $addressItem) {
64+
if ($addressItem instanceof \Magento\Quote\Model\Quote\Item) {
65+
$itemId = $addressItem->getItemId();
66+
} else {
67+
$itemId = $addressItem->getQuoteItemId();
68+
}
69+
6470
$addressItemsData[] = [
65-
'cart_item_id' => $addressItem->getQuoteItemId(),
71+
'cart_item_id' => $itemId,
6672
'quantity' => $addressItem->getQty()
6773
];
6874
}

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

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -139,29 +139,33 @@ private function getQuery(string $maskedQuoteId): string
139139
query {
140140
cart (cart_id: "{$maskedQuoteId}") {
141141
shipping_addresses {
142-
available_shipping_methods {
143-
amount {
144-
value
145-
currency
146-
}
147-
base_amount {
148-
value
149-
currency
150-
}
151-
carrier_code
152-
carrier_title
153-
error_message
154-
method_code
155-
method_title
156-
price_excl_tax {
157-
value
158-
currency
159-
}
160-
price_incl_tax {
161-
value
162-
currency
163-
}
142+
cart_items {
143+
cart_item_id
144+
quantity
145+
}
146+
available_shipping_methods {
147+
amount {
148+
value
149+
currency
164150
}
151+
base_amount {
152+
value
153+
currency
154+
}
155+
carrier_code
156+
carrier_title
157+
error_message
158+
method_code
159+
method_title
160+
price_excl_tax {
161+
value
162+
currency
163+
}
164+
price_incl_tax {
165+
value
166+
currency
167+
}
168+
}
165169
}
166170
}
167171
}

0 commit comments

Comments
 (0)