From b3f510d037dffb62b70fb14d7f3fba63b9670a43 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 4 Sep 2019 11:29:54 +0300 Subject: [PATCH 1/8] graphQl-890: Replaced usage of the CartItemQuantity with the CartItemInterface --- .../Magento/QuoteGraphQl/etc/schema.graphqls | 6 ++-- .../Customer/AddSimpleProductToCartTest.php | 30 +++++++++++++++++++ .../Guest/AddSimpleProductToCartTest.php | 30 +++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index c458b5e9dc05d..d7741c392e9f7 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -216,14 +216,14 @@ 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] + items_weight: Float @deprecated + cart_items: [CartItemInterface] } type BillingCartAddress implements CartAddressInterface { } -type CartItemQuantity { +type CartItemQuantity @deprecated(reason: "Use CartItemInterface instead") { cart_item_id: Int! quantity: Float! } 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..19251b3741106 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 @@ -52,6 +52,22 @@ public function testAddSimpleProductToCart() self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']); 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']); + self::assertArrayHasKey('value', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']); + self::assertEquals(10, $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']['value']); + self::assertEquals('USD', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']['currency']); + + self::assertArrayHasKey('row_total', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']); + self::assertArrayHasKey('value', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']); + self::assertEquals(20, $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']['value']); + self::assertEquals('USD', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']['currency']); + + self::assertArrayHasKey('row_total_including_tax', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']); + self::assertArrayHasKey('value', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']); + self::assertEquals(20, $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']['value']); + self::assertEquals('USD', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']['currency']); } /** @@ -262,6 +278,20 @@ 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 + } + } } } } 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..cc7365fb7bcf2 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 @@ -47,6 +47,22 @@ public function testAddSimpleProductToCart() 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']); + self::assertArrayHasKey('value', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']); + self::assertEquals(10, $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']['value']); + self::assertEquals('USD', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']['currency']); + + self::assertArrayHasKey('row_total', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']); + self::assertArrayHasKey('value', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']); + self::assertEquals(20, $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']['value']); + self::assertEquals('USD', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']['currency']); + + self::assertArrayHasKey('row_total_including_tax', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']); + self::assertArrayHasKey('value', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']); + self::assertEquals(20, $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']['value']); + self::assertEquals('USD', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']['currency']); } /** @@ -231,6 +247,20 @@ 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 + } + } } } } From f7ab08e6103ad1a1b503b6226e9edad53f6e7700 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 4 Sep 2019 11:56:31 +0300 Subject: [PATCH 2/8] graphQl-890: fixed static tests --- .../Customer/AddSimpleProductToCartTest.php | 30 ++++++++++++------- .../Guest/AddSimpleProductToCartTest.php | 30 ++++++++++++------- 2 files changed, 40 insertions(+), 20 deletions(-) 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 19251b3741106..f861b9db98fe7 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 @@ -55,19 +55,29 @@ public function testAddSimpleProductToCart() self::assertArrayHasKey('prices', $response['addSimpleProductsToCart']['cart']['items'][0]); self::assertArrayHasKey('price', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']); - self::assertArrayHasKey('value', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']); - self::assertEquals(10, $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']['value']); - self::assertEquals('USD', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']['currency']); + $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']); - self::assertArrayHasKey('value', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']); - self::assertEquals(20, $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']['value']); - self::assertEquals('USD', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']['currency']); + $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']); - self::assertArrayHasKey('value', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']); - self::assertEquals(20, $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']['value']); - self::assertEquals('USD', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']['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']); } /** 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 cc7365fb7bcf2..1a3a1c8a738e5 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 @@ -50,19 +50,29 @@ public function testAddSimpleProductToCart() self::assertArrayHasKey('prices', $response['addSimpleProductsToCart']['cart']['items'][0]); self::assertArrayHasKey('price', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']); - self::assertArrayHasKey('value', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']); - self::assertEquals(10, $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']['value']); - self::assertEquals('USD', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price']['currency']); + $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']); - self::assertArrayHasKey('value', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']); - self::assertEquals(20, $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']['value']); - self::assertEquals('USD', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total']['currency']); + $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']); - self::assertArrayHasKey('value', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']); - self::assertEquals(20, $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']['value']); - self::assertEquals('USD', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax']['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']); } /** From 863d178be4baf88fffc7b252c0a92f6edb0410e5 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Fri, 27 Sep 2019 10:57:22 +0300 Subject: [PATCH 3/8] graphQl-890: fixed deprecation messages --- app/code/Magento/QuoteGraphQl/etc/schema.graphqls | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index 2edb3f1e196ab..cd72e90344c6f 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -220,7 +220,7 @@ 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") customer_notes: String - items_weight: Float @deprecated + items_weight: Float @deprecated(reason: "This information shoud not be exposed on frontend") cart_items: [CartItemInterface] } @@ -228,7 +228,7 @@ type BillingCartAddress implements CartAddressInterface { customer_notes: String @deprecated (reason: "The field is used only in shipping address") } -type CartItemQuantity @deprecated(reason: "Use CartItemInterface instead") { +type CartItemQuantity @deprecated(reason: "All fields in CartItemQuantity should be deprecated (so this type can be completely removed in the future releases)") { cart_item_id: Int! quantity: Float! } From 62971990536fea8aadb9eb91f407c4b7eda61d10 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Sun, 20 Oct 2019 21:11:56 +0300 Subject: [PATCH 4/8] GraphQl-890: added shipping addresses to tests --- .../Customer/AddSimpleProductToCartTest.php | 16 ++++++++++++++++ .../Quote/Guest/AddSimpleProductToCartTest.php | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) 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 f861b9db98fe7..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,6 +50,8 @@ 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]); @@ -303,6 +305,20 @@ private function getQuery(string $maskedQuoteId, string $sku, float $quantity): } } } + 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 1a3a1c8a738e5..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,6 +45,8 @@ 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]); @@ -272,6 +274,20 @@ private function getQuery(string $maskedQuoteId, string $sku, float $quantity): } } } + shipping_addresses { + firstname + lastname + company + street + city + postcode + telephone + country { + code + label + } + __typename + } } } } From 795931f1bb0ca75389a974710d4dfff37561af00 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Wed, 23 Oct 2019 14:14:48 -0500 Subject: [PATCH 5/8] magento/graphql-ce#890: [Checkout] Replace usage of CartItemQuantity with CartItemInterface --- app/code/Magento/QuoteGraphQl/etc/schema.graphqls | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index cd72e90344c6f..494af6c633efa 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -228,9 +228,9 @@ type BillingCartAddress implements CartAddressInterface { customer_notes: String @deprecated (reason: "The field is used only in shipping address") } -type CartItemQuantity @deprecated(reason: "All fields in CartItemQuantity should be deprecated (so this type can be completely removed in the future releases)") { - 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 { From 8b51315687fe2891ed731ef821c0719a6d995765 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Wed, 23 Oct 2019 15:50:26 -0500 Subject: [PATCH 6/8] magento/graphql-ce#890: [Checkout] Replace usage of CartItemQuantity with CartItemInterface --- .../QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php | 9 ++++++--- .../Quote/Guest/GetAvailableShippingMethodsTest.php | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php b/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php index 27dd1959cb5d7..86e00bfe42c81 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php @@ -68,10 +68,13 @@ public function execute(QuoteAddress $address): array } else { $itemId = $addressItem->getQuoteItemId(); } - + $productData = $addressItem->getProduct()->getData(); + $productData['model'] = $addressItem->getProduct(); $addressItemsData[] = [ - 'cart_item_id' => $itemId, - 'quantity' => $addressItem->getQty() + 'id' => $itemId, + 'quantity' => $addressItem->getQty(), + 'product' => $productData, + 'model' => $addressItem, ]; } $addressData['cart_items'] = $addressItemsData; 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..f076c0aaa4678 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 @@ -137,8 +137,11 @@ private function getQuery(string $maskedQuoteId): string cart (cart_id: "{$maskedQuoteId}") { shipping_addresses { cart_items { - cart_item_id + id quantity + product { + sku + } } available_shipping_methods { amount { From 344648f002ecbd5ced22680e445ce4dfa82d3637 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Wed, 23 Oct 2019 16:43:07 -0500 Subject: [PATCH 7/8] magento/graphql-ce#890: [Checkout] Replace usage of CartItemQuantity with CartItemInterface --- .../QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php | 9 +++++---- app/code/Magento/QuoteGraphQl/etc/schema.graphqls | 3 ++- .../Quote/Guest/GetAvailableShippingMethodsTest.php | 7 +++++++ 3 files changed, 14 insertions(+), 5 deletions(-) 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 { From b9f708bc25f4cb389bdb3e109e01a543d4179a85 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Wed, 23 Oct 2019 17:03:37 -0500 Subject: [PATCH 8/8] magento/graphql-ce#890: [Checkout] Replace usage of CartItemQuantity with CartItemInterface --- .../GraphQl/Quote/Guest/GetAvailableShippingMethodsTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 1d477666d3d8b..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 @@ -75,7 +75,10 @@ public function testGetAvailableShippingMethods() ); 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']); + self::assertEquals( + 'simple_product', + $response['cart']['shipping_addresses'][0]['cart_items_v2'][0]['product']['sku'] + ); } /**