Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit 0173252

Browse files
authored
ENGCOM-4256: Add virtual products to cart #320
2 parents 6a63e3b + 66659cf commit 0173252

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/ExtractDataFromCart.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,36 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10+
use Magento\Framework\Exception\NoSuchEntityException;
1011
use Magento\Quote\Model\Quote;
1112
use Magento\Quote\Model\Quote\Item as QuoteItem;
13+
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1214

1315
/**
1416
* Extract data from cart
1517
*/
1618
class ExtractDataFromCart
1719
{
20+
/**
21+
* @var QuoteIdToMaskedQuoteIdInterface
22+
*/
23+
private $quoteIdToMaskedQuoteId;
24+
25+
/**
26+
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
27+
*/
28+
public function __construct(
29+
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
30+
) {
31+
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
32+
}
33+
1834
/**
1935
* Extract data from cart
2036
*
2137
* @param Quote $cart
2238
* @return array
39+
* @throws NoSuchEntityException
2340
*/
2441
public function execute(Quote $cart): array
2542
{
@@ -43,6 +60,7 @@ public function execute(Quote $cart): array
4360
$appliedCoupon = $cart->getCouponCode();
4461

4562
return [
63+
'cart_id' => $this->quoteIdToMaskedQuoteId->execute((int)$cart->getId()),
4664
'items' => $items,
4765
'applied_coupon' => $appliedCoupon ? ['code' => $appliedCoupon] : null
4866
];

app/code/Magento/QuoteGraphQl/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<arguments>
1212
<argument name="supportedTypes" xsi:type="array">
1313
<item name="simple" xsi:type="string">SimpleCartItem</item>
14+
<item name="virtual" xsi:type="string">VirtualCartItem</item>
1415
</argument>
1516
</arguments>
1617
</type>

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Mutation {
1515
setBillingAddressOnCart(input: SetBillingAddressOnCartInput): SetBillingAddressOnCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetBillingAddressOnCart")
1616
setShippingMethodsOnCart(input: SetShippingMethodsOnCartInput): SetShippingMethodsOnCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetShippingMethodsOnCart")
1717
addSimpleProductsToCart(input: AddSimpleProductsToCartInput): AddSimpleProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart")
18+
addVirtualProductsToCart(input: AddVirtualProductsToCartInput): AddVirtualProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart")
1819
}
1920

2021
input SetShippingAddressesOnCartInput {
@@ -168,11 +169,21 @@ input AddSimpleProductsToCartInput {
168169
cartItems: [SimpleProductCartItemInput!]!
169170
}
170171

172+
input AddVirtualProductsToCartInput {
173+
cart_id: String!
174+
cartItems: [VirtualProductCartItemInput!]!
175+
}
176+
171177
input SimpleProductCartItemInput {
172178
data: CartItemInput!
173179
customizable_options:[CustomizableOptionInput!]
174180
}
175181

182+
input VirtualProductCartItemInput {
183+
data: CartItemInput!
184+
customizable_options:[CustomizableOptionInput!]
185+
}
186+
176187
input CustomizableOptionInput {
177188
id: Int!
178189
value: String!
@@ -182,10 +193,18 @@ type AddSimpleProductsToCartOutput {
182193
cart: Cart!
183194
}
184195

196+
type AddVirtualProductsToCartOutput {
197+
cart: Cart!
198+
}
199+
185200
type SimpleCartItem implements CartItemInterface @doc(description: "Simple Cart Item") {
186201
customizable_options: [SelectedCustomizableOption] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
187202
}
188203

204+
type VirtualCartItem implements CartItemInterface @doc(description: "Virtual Cart Item") {
205+
customizable_options: [SelectedCustomizableOption] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
206+
}
207+
189208
input CartItemInput {
190209
sku: String!
191210
qty: Float!

0 commit comments

Comments
 (0)