Skip to content

Commit

Permalink
ENGCOM-5772: graphQl-890: Replaced usage of the CartItemQuantity with…
Browse files Browse the repository at this point in the history
… the CartItem… #899

 - Merge Pull Request magento/graphql-ce#899 from magento/graphql-ce:GraphQl-890-Replaced-usage-of-CartItemQuantity-with-CartItemInterface
 - Merged commits:
   1. b3f510d
   2. f7ab08e
   3. 94e8f14
   4. 77e3a9c
   5. 863d178
   6. 6297199
   7. 795931f
   8. c9c13a6
   9. 8b51315
   10. 344648f
   11. b9f708b
  • Loading branch information
magento-engcom-team committed Oct 28, 2019
2 parents 68d2137 + b9f708b commit 48e175b
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
11 changes: 6 additions & 5 deletions app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
}

/**
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 48e175b

Please sign in to comment.