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

Adjust adding configurable products to the shopping cart #438

Closed
rogyar opened this issue Mar 5, 2019 · 2 comments
Closed

Adjust adding configurable products to the shopping cart #438

rogyar opened this issue Mar 5, 2019 · 2 comments
Labels
Checkout Component: QuoteGraphQl Contribution Day Tickets is good for start on Contribution Day good first issue Good for newcomers

Comments

@rogyar
Copy link
Contributor

rogyar commented Mar 5, 2019

Desciption

Currently, we use the same approach for adding configurable products to the shopping cart as for the simple products. As result, we are able to add only simple products using addConfigurableProductsToCart mutation.

Take a look at the following mutation:

mutation {
  addConfigurableProductsToCart(
    input: {
      cart_id: "{{ CART_ID }}"
      cartItems: [
        {
          variant_sku: "useless-field"
          data: {
            qty: 11
            sku: "configurable-product-option1"
          }
        }
        {
          variant_sku: "useless-field"
          data: {
            qty: 11
            sku: "configurable-product-option2"
          }
        }
      ]
    }
  ) {
    cart {
      items {
        qty
      }
    }
  }
}

configurable-product-option1 and configurable-product-option2 are SKUs of the simple products. There's no mention about a configurable product that we are going to add to the shopping cart. variant_sku is not being processed in resolvers or somewhere else. So, yes, this field is useless.
After using the mentioned query we will have two simple products in the shopping cart (configurable-product-option1 , configurable-product-option2) but zero configurable products.

Ideally, the mutation should have the following look:

mutation {
  addConfigurableProductsToCart(
    input: {
      cart_id: "{{ CART_ID }}"
      cartItems: [
        {
          variant_sku: "configurable-product-option1"
          data: {
            qty: 11
            sku: "configurable-product-sku"
          }
        }
        {
          variant_sku: ""configurable-product-option2"
          data: {
            qty: 11
            sku: "configurable-product-sku"
          }
        }
      ]
    }
  ) {
    cart {
      items {
        qty
      }
    }
  }
}

In this case, we would have two configurable parent products in the cart and two corresponding simple items. This scenario corresponds to the scenario we have currently in storefront->backend flow.
But, as it was mentioned, this query will not work since variant_sku is not processed.

We could simply add variant_sku processing. But, unfortunately, things are not that easy.
In order to create a correct buy request for a configurable product (https://github.com/magento/graphql-ce/blob/2.3-develop/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php#L79) we need to pass super attributes values of the configurable product to this request, but not SKU of a child product.
The storefront is designed in the following way:

  • On a configurable product page, we see super attributes (not child simple products)
  • Customer selects super attributes values and adds configurable product to the shopping cart
  • On the backend side the super attributes and their values are converted to the simple product that is being added alongside to the configurable product.

From the PWA perspective, I believe we should use a similar approach. Instead of possibility to pass a child product's SKU we should use super attributes (unless child products are going to be shown instead of attributes on a configurable PDP)

So the schema will look something like:

mutation {
  addConfigurableProductsToCart(
    input: {
      cart_id: "{{ CART_ID }}"
      cartItems: [
        {
          configurable_attributes {[
          {
              id: $id
              value: $value
          }
          {
              id: $id
              value: $value
          }
          ]}
          data: {
            qty: 11
            sku: "configurable-product-sku"
          }
        }
      ]
    }
  ) {
    cart {
      items {
        qty
      }
    }
  }
}

Current GraphQl schema and resolvers don't respect this flow and we have no information about selected super attributes. So we cannot pass this information to the buy request. We have SKU of the child product but It's really hard to convert SKU -> supper attributes:values. The system designed to process it in reverse order: super attributes:values -> SKU.

@naydav
Copy link
Contributor

naydav commented Apr 24, 2019

@rogyar You vision is absolutely correct
Moreover, it was described in initial scheme proposal
https://github.com/magento/architecture/blob/master/design-documents/graph-ql/coverage/add-items-to-cart/AddConfigurableProductToCart.graphqls#L22

So, we need to have implement support of

mutation {
  addConfigurableProductsToCart(
    input: {
      cart_id: "{{ CART_ID }}"
      cartItems: [
        {
          variant_sku: "configurable-product-option1"
          data: {
            qty: 11
            sku: "configurable-product-sku"
          }
        }
        {
          variant_sku: ""configurable-product-option2"
          data: {
            qty: 11
            sku: "configurable-product-sku"
          }
        }
      ]
    }
  ) {
    cart {
      items {
        qty
      }
    }
  }
}

@naydav naydav assigned rogyar and unassigned rogyar Apr 24, 2019
@naydav naydav added Checkout Contribution Day Tickets is good for start on Contribution Day good first issue Good for newcomers and removed bug Something isn't working labels May 2, 2019
@naydav naydav added this to the Release: 2.3.3 milestone May 2, 2019
@pmclain pmclain self-assigned this May 4, 2019
pmclain added a commit to pmclain/graphql-ce that referenced this issue May 11, 2019
Allows adding configurable products to cart in the same manner as the current
Magento storefront.

Fixes magento#438
pmclain added a commit to pmclain/graphql-ce that referenced this issue May 17, 2019
Allows adding configurable products to cart in the same manner as the current
Magento storefront.

Fixes magento#438
@naydav
Copy link
Contributor

naydav commented Jul 30, 2019

#699

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Checkout Component: QuoteGraphQl Contribution Day Tickets is good for start on Contribution Day good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants