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

Conversation

rogyar
Copy link
Contributor

@rogyar rogyar commented Jan 23, 2019

Description (*)

This PR adds a possibility to add virtual products to the shopping cart

Fixed Issues (if relevant)

  1. [Cart Operations] Add virtual product to Cart #145: [Cart Operations] Add virtual product to Cart

Manual testing scenarios (*)

Use the following query with your own values to add a virtual product

mutation {
  addVirtualProductsToCart(
    input: {
      cart_id: "JJErKhk2dtVa7BOyJDxPH2fv0DcGZkA1", 
      cartItems: [
        {
          data: {
            sku: "virt", 
            qty: 2
          }          
        }
      ]
    }
  ) {
    cart {
      cart_id
      items {
        id
      }
    }
  }
}

Copy link
Contributor Author

@rogyar rogyar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naydav Could you check my questions in the review, please? Thanks

@@ -15,6 +15,7 @@ type Mutation {
setBillingAddressOnCart(input: SetBillingAddressOnCartInput): SetBillingAddressOnCartOutput
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\\AddVirtualProductsToCart")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we reuse resolver from addSimpleProductsToCart (rename in order to have a more universal name) here? Resolvers for simple and virtual products are identical.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we need to reuse configurable for simple because the code is the same (and we will have copy paste detector fail)

*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
$cartHash = $this->arrayManager->get('input/cart_id', $args);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are not going to use the resolver for virtual/simple products, should we add an additional check for the product type in a resolver?
Currently we can add simple product via virtual product mutation and vice versa

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to have 2 different resolvers with checking of product type, but all general logic should be moved to Model in a separate class

Also, need to cover functionality with API-functional tests (including negative scenarios with a wrong product type)
Thanks

@ghost
Copy link

ghost commented Feb 14, 2019

Hi @rogyar, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@keharper
Copy link
Contributor

Documented as part of magento/devdocs#4502

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants