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

Add virtual products to cart #320

Merged
merged 4 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/code/Magento/QuoteGraphQl/Model/Cart/ExtractDataFromCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,36 @@

namespace Magento\QuoteGraphQl\Model\Cart;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\Quote\Item as QuoteItem;
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;

/**
* Extract data from cart
*/
class ExtractDataFromCart
{
/**
* @var QuoteIdToMaskedQuoteIdInterface
*/
private $quoteIdToMaskedQuoteId;

/**
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
*/
public function __construct(
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
) {
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
}

/**
* Extract data from cart
*
* @param Quote $cart
* @return array
* @throws NoSuchEntityException
*/
public function execute(Quote $cart): array
{
Expand All @@ -43,6 +60,7 @@ public function execute(Quote $cart): array
$appliedCoupon = $cart->getCouponCode();

return [
'cart_id' => $this->quoteIdToMaskedQuoteId->execute((int)$cart->getId()),
'items' => $items,
'applied_coupon' => $appliedCoupon ? ['code' => $appliedCoupon] : null
];
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/QuoteGraphQl/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<arguments>
<argument name="supportedTypes" xsi:type="array">
<item name="simple" xsi:type="string">SimpleCartItem</item>
<item name="virtual" xsi:type="string">VirtualCartItem</item>
</argument>
</arguments>
</type>
Expand Down
19 changes: 19 additions & 0 deletions app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Mutation {
setBillingAddressOnCart(input: SetBillingAddressOnCartInput): SetBillingAddressOnCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetBillingAddressOnCart")
setShippingMethodsOnCart(input: SetShippingMethodsOnCartInput): SetShippingMethodsOnCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetShippingMethodsOnCart")
addSimpleProductsToCart(input: AddSimpleProductsToCartInput): AddSimpleProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart")
addVirtualProductsToCart(input: AddVirtualProductsToCartInput): AddVirtualProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart")
}

input SetShippingAddressesOnCartInput {
Expand Down Expand Up @@ -168,11 +169,21 @@ input AddSimpleProductsToCartInput {
cartItems: [SimpleProductCartItemInput!]!
}

input AddVirtualProductsToCartInput {
cart_id: String!
cartItems: [VirtualProductCartItemInput!]!
}

input SimpleProductCartItemInput {
data: CartItemInput!
customizable_options:[CustomizableOptionInput!]
}

input VirtualProductCartItemInput {
data: CartItemInput!
customizable_options:[CustomizableOptionInput!]
}

input CustomizableOptionInput {
id: Int!
value: String!
Expand All @@ -182,10 +193,18 @@ type AddSimpleProductsToCartOutput {
cart: Cart!
}

type AddVirtualProductsToCartOutput {
cart: Cart!
}

type SimpleCartItem implements CartItemInterface @doc(description: "Simple Cart Item") {
customizable_options: [SelectedCustomizableOption] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
}

type VirtualCartItem implements CartItemInterface @doc(description: "Virtual Cart Item") {
customizable_options: [SelectedCustomizableOption] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
}

input CartItemInput {
sku: String!
qty: Float!
Expand Down