Skip to content

Commit

Permalink
magento/graphql-ce#890: [Checkout] Replace usage of CartItemQuantity …
Browse files Browse the repository at this point in the history
…with CartItemInterface
  • Loading branch information
lenaorobei committed Oct 23, 2019
1 parent 8b51315 commit 344648f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
}
3 changes: 2 additions & 1 deletion app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

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

0 comments on commit 344648f

Please sign in to comment.