diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php b/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php index 27dd1959cb5d7..468ef4b8f879c 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php @@ -61,21 +61,25 @@ 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(); } else { $itemId = $addressItem->getQuoteItemId(); } - - $addressItemsData[] = [ + $productData = $addressItem->getProduct()->getData(); + $productData['model'] = $addressItem->getProduct(); + $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 0f818984ebda4..afdb08ebab915 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -219,18 +219,19 @@ interface CartAddressInterface @typeResolver(class: "\\Magento\\QuoteGraphQl\\Mo type ShippingCartAddress implements CartAddressInterface { available_shipping_methods: [AvailableShippingMethod] @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ShippingAddress\\AvailableShippingMethods") selected_shipping_method: SelectedShippingMethod @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ShippingAddress\\SelectedShippingMethod") - items_weight: Float - cart_items: [CartItemQuantity] customer_notes: String + items_weight: Float @deprecated(reason: "This information shoud not be exposed on frontend") + cart_items: [CartItemQuantity] @deprecated(reason: "`cart_items_v2` should be used instead") + cart_items_v2: [CartItemInterface] } type BillingCartAddress implements CartAddressInterface { customer_notes: String @deprecated (reason: "The field is used only in shipping address") } -type CartItemQuantity { - cart_item_id: Int! - quantity: Float! +type CartItemQuantity @doc(description:"Deprecated: `cart_items` field of `ShippingCartAddress` returns now `CartItemInterface` instead of `CartItemQuantity`") { + cart_item_id: Int! @deprecated(reason: "`cart_items` field of `ShippingCartAddress` returns now `CartItemInterface` instead of `CartItemQuantity`") + quantity: Float! @deprecated(reason: "`cart_items` field of `ShippingCartAddress` returns now `CartItemInterface` instead of `CartItemQuantity`") } type CartAddressRegion { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/AddSimpleProductToCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/AddSimpleProductToCartTest.php index e1b93e0bdb857..f7ba5b4d924fb 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/AddSimpleProductToCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/AddSimpleProductToCartTest.php @@ -50,8 +50,36 @@ public function testAddSimpleProductToCart() $response = $this->graphQlMutation($query, [], '', $this->getHeaderMap()); self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']); + self::assertArrayHasKey('shipping_addresses', $response['addSimpleProductsToCart']['cart']); + self::assertEmpty($response['addSimpleProductsToCart']['cart']['shipping_addresses']); self::assertEquals($quantity, $response['addSimpleProductsToCart']['cart']['items'][0]['quantity']); self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']); + self::assertArrayHasKey('prices', $response['addSimpleProductsToCart']['cart']['items'][0]); + + self::assertArrayHasKey('price', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']); + $price = $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']; + self::assertArrayHasKey('value', $price); + self::assertEquals(10, $price['value']); + self::assertArrayHasKey('currency', $price); + self::assertEquals('USD', $price['currency']); + + self::assertArrayHasKey('row_total', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']); + $rowTotal = $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']; + self::assertArrayHasKey('value', $rowTotal); + self::assertEquals(20, $rowTotal['value']); + self::assertArrayHasKey('currency', $rowTotal); + self::assertEquals('USD', $rowTotal['currency']); + + self::assertArrayHasKey( + 'row_total_including_tax', + $response['addSimpleProductsToCart']['cart']['items'][0]['prices'] + ); + $rowTotalIncludingTax = + $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']; + self::assertArrayHasKey('value', $rowTotalIncludingTax); + self::assertEquals(20, $rowTotalIncludingTax['value']); + self::assertArrayHasKey('currency', $rowTotalIncludingTax); + self::assertEquals('USD', $rowTotalIncludingTax['currency']); } /** @@ -262,6 +290,34 @@ private function getQuery(string $maskedQuoteId, string $sku, float $quantity): product { sku } + prices { + price { + value + currency + } + row_total { + value + currency + } + row_total_including_tax { + value + currency + } + } + } + shipping_addresses { + firstname + lastname + company + street + city + postcode + telephone + country { + code + label + } + __typename } } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/AddSimpleProductToCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/AddSimpleProductToCartTest.php index 4deed99243f9d..5f65ac666ab97 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/AddSimpleProductToCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/AddSimpleProductToCartTest.php @@ -45,8 +45,36 @@ public function testAddSimpleProductToCart() $response = $this->graphQlMutation($query); self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']); + self::assertArrayHasKey('shipping_addresses', $response['addSimpleProductsToCart']['cart']); + self::assertEmpty($response['addSimpleProductsToCart']['cart']['shipping_addresses']); self::assertEquals($quantity, $response['addSimpleProductsToCart']['cart']['items'][0]['quantity']); self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']); + self::assertArrayHasKey('prices', $response['addSimpleProductsToCart']['cart']['items'][0]); + + self::assertArrayHasKey('price', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']); + $price = $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']; + self::assertArrayHasKey('value', $price); + self::assertEquals(10, $price['value']); + self::assertArrayHasKey('currency', $price); + self::assertEquals('USD', $price['currency']); + + self::assertArrayHasKey('row_total', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']); + $rowTotal = $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']; + self::assertArrayHasKey('value', $rowTotal); + self::assertEquals(20, $rowTotal['value']); + self::assertArrayHasKey('currency', $rowTotal); + self::assertEquals('USD', $rowTotal['currency']); + + self::assertArrayHasKey( + 'row_total_including_tax', + $response['addSimpleProductsToCart']['cart']['items'][0]['prices'] + ); + $rowTotalIncludingTax = + $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']; + self::assertArrayHasKey('value', $rowTotalIncludingTax); + self::assertEquals(20, $rowTotalIncludingTax['value']); + self::assertArrayHasKey('currency', $rowTotalIncludingTax); + self::assertEquals('USD', $rowTotalIncludingTax['currency']); } /** @@ -231,6 +259,34 @@ private function getQuery(string $maskedQuoteId, string $sku, float $quantity): product { sku } + prices { + price { + value + currency + } + row_total { + value + currency + } + row_total_including_tax { + value + currency + } + } + } + shipping_addresses { + firstname + lastname + company + street + city + postcode + telephone + country { + code + label + } + __typename } } } 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 0d64d73965d2b..867aaab7b3a58 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,12 @@ 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'] + ); } /** @@ -140,6 +146,13 @@ private function getQuery(string $maskedQuoteId): string cart_item_id quantity } + cart_items_v2 { + id + quantity + product { + sku + } + } available_shipping_methods { amount { value