diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php b/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php index 86e00bfe42c81..468ef4b8f879c 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php @@ -61,7 +61,6 @@ public function execute(QuoteAddress $address): array return $addressData; } - $addressItemsData = []; foreach ($address->getAllItems() as $addressItem) { if ($addressItem instanceof \Magento\Quote\Model\Quote\Item) { $itemId = $addressItem->getItemId(); @@ -70,15 +69,17 @@ public function execute(QuoteAddress $address): array } $productData = $addressItem->getProduct()->getData(); $productData['model'] = $addressItem->getProduct(); - $addressItemsData[] = [ + $addressData['cart_items'][] = [ + 'cart_item_id' => $itemId, + 'quantity' => $addressItem->getQty() + ]; + $addressData['cart_items_v2'][] = [ 'id' => $itemId, 'quantity' => $addressItem->getQty(), 'product' => $productData, 'model' => $addressItem, ]; } - $addressData['cart_items'] = $addressItemsData; - return $addressData; } } diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index 7074be249fbca..afdb08ebab915 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -221,7 +221,8 @@ type ShippingCartAddress implements CartAddressInterface { selected_shipping_method: SelectedShippingMethod @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ShippingAddress\\SelectedShippingMethod") customer_notes: String items_weight: Float @deprecated(reason: "This information shoud not be exposed on frontend") - cart_items: [CartItemInterface] + cart_items: [CartItemQuantity] @deprecated(reason: "`cart_items_v2` should be used instead") + cart_items_v2: [CartItemInterface] } type BillingCartAddress implements CartAddressInterface { 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 f076c0aaa4678..1d477666d3d8b 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 @@ -73,6 +73,9 @@ public function testGetAvailableShippingMethods() $expectedAddressData, $response['cart']['shipping_addresses'][0]['available_shipping_methods'][0] ); + self::assertCount(1, $response['cart']['shipping_addresses'][0]['cart_items']); + self::assertCount(1, $response['cart']['shipping_addresses'][0]['cart_items_v2']); + self::assertEquals('simple_product', $response['cart']['shipping_addresses'][0]['cart_items_v2'][0]['product']['sku']); } /** @@ -137,6 +140,10 @@ private function getQuery(string $maskedQuoteId): string cart (cart_id: "{$maskedQuoteId}") { shipping_addresses { cart_items { + cart_item_id + quantity + } + cart_items_v2 { id quantity product {