Skip to content

Commit

Permalink
Correct cart_item_id source for address items
Browse files Browse the repository at this point in the history
[`\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
  • Loading branch information
pmclain committed Aug 24, 2019
1 parent e56640c commit f0bb8d5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ public function execute(QuoteAddress $address): array

$addressItemsData = [];
foreach ($address->getAllItems() as $addressItem) {
if ($addressItem instanceof \Magento\Quote\Model\Quote\Item) {
$itemId = $addressItem->getItemId();
} else {
$itemId = $addressItem->getQuoteItemId();
}

$addressItemsData[] = [
'cart_item_id' => $addressItem->getQuoteItemId(),
'cart_item_id' => $itemId,
'quantity' => $addressItem->getQty()
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,29 +139,33 @@ private function getQuery(string $maskedQuoteId): string
query {
cart (cart_id: "{$maskedQuoteId}") {
shipping_addresses {
available_shipping_methods {
amount {
value
currency
}
base_amount {
value
currency
}
carrier_code
carrier_title
error_message
method_code
method_title
price_excl_tax {
value
currency
}
price_incl_tax {
value
currency
}
cart_items {
cart_item_id
quantity
}
available_shipping_methods {
amount {
value
currency
}
base_amount {
value
currency
}
carrier_code
carrier_title
error_message
method_code
method_title
price_excl_tax {
value
currency
}
price_incl_tax {
value
currency
}
}
}
}
}
Expand Down

0 comments on commit f0bb8d5

Please sign in to comment.