diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php b/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php index c4d795293220f..27dd1959cb5d7 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php @@ -7,7 +7,6 @@ namespace Magento\QuoteGraphQl\Model\Cart; -use Magento\Customer\Model\Address\AbstractAddress; use Magento\Framework\Api\ExtensibleDataObjectConverter; use Magento\Quote\Api\Data\AddressInterface; use Magento\Quote\Model\Quote\Address as QuoteAddress; @@ -41,19 +40,22 @@ public function execute(QuoteAddress $address): array $addressData = $this->dataObjectConverter->toFlatArray($address, [], AddressInterface::class); $addressData['model'] = $address; - $addressData = array_merge($addressData, [ - 'country' => [ - 'code' => $address->getCountryId(), - 'label' => $address->getCountry() - ], - 'region' => [ - 'code' => $address->getRegionCode(), - 'label' => $address->getRegion() - ], - 'street' => $address->getStreet(), - 'items_weight' => $address->getWeight(), - 'customer_notes' => $address->getCustomerNotes() - ]); + $addressData = array_merge( + $addressData, + [ + 'country' => [ + 'code' => $address->getCountryId(), + 'label' => $address->getCountry() + ], + 'region' => [ + 'code' => $address->getRegionCode(), + 'label' => $address->getRegion() + ], + 'street' => $address->getStreet(), + 'items_weight' => $address->getWeight(), + 'customer_notes' => $address->getCustomerNotes() + ] + ); if (!$address->hasItems()) { return $addressData; @@ -61,8 +63,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() ]; } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php index 81222a84435c8..0d64d73965d2b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php @@ -67,6 +67,7 @@ public function testGetAvailableShippingMethods() 'value' => 10, 'currency' => 'USD', ], + 'base_amount' => null, ]; self::assertEquals( $expectedAddressData, @@ -135,25 +136,46 @@ private function getQuery(string $maskedQuoteId): string query { cart (cart_id: "{$maskedQuoteId}") { shipping_addresses { - available_shipping_methods { - 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 } + carrier_code + carrier_title + error_message + method_code + method_title + price_excl_tax { + value + currency + } + price_incl_tax { + 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 + } + } } } }