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

addConfigurableProductToCart Fails Adding Multiple Items #854

Closed
pmclain opened this issue Aug 24, 2019 · 2 comments
Closed

addConfigurableProductToCart Fails Adding Multiple Items #854

pmclain opened this issue Aug 24, 2019 · 2 comments
Assignees
Labels
Projects

Comments

@pmclain
Copy link
Contributor

pmclain commented Aug 24, 2019

Preconditions (*)

  1. Create configurable product with at least two variants

Steps to reproduce (*)

  1. Create empty cart
  2. Execute mutation adding multiple variants to empty cart
mutation addConfigurableProductsToCart($cartId:String!) {
  addConfigurableProductsToCart(input:{
    cart_id:$cartId
    cart_items:[
      {
        parent_sku:"Configurable Product 1"
        data:{
          sku:"Configurable Product 1 - option 1"
          quantity:2
        }
      },
      {
        parent_sku:"Configurable Product 1"
        data:{
          sku:"Configurable Product 1 - option 2"
          quantity:1
        }
      }
    ]
  }) {
    cart {
      items {
        id
        quantity
        product {
          sku
        }
        ... on ConfigurableCartItem {
          configurable_options {
            option_label
            value_label
          }
        }
      }
    }
  }
}

Expected result (*)

Response contains requested items and their respective quantities

{
  "data": {
    "addConfigurableProductsToCart": {
      "cart": {
        "items": [
          {
            "id": "1",
            "quantity": 2,
            "product": {
              "sku": "Configurable Product 1"
            },
            "configurable_options": [
              {
                "option_label": "Dynamic Attribute ca_1_631447041",
                "value_label": "option 1"
              },
              {
                "option_label": "Dynamic Attribute ca_2_631447041",
                "value_label": "option 1"
              }
            ]
          },
          {
            "id": "4",
            "quantity": 1,
            "product": {
              "sku": "Configurable Product 1"
            },
            "configurable_options": [
              {
                "option_label": "Dynamic Attribute ca_1_631447041",
                "value_label": "option 1"
              },
              {
                "option_label": "Dynamic Attribute ca_2_631447041",
                "value_label": "option 2"
              }
            ]
          }
        ]
      }
    }
  }
}

Actual result (*)

A single item is added to the cart with a quantity of the summed request item quantities

{
  "data": {
    "addConfigurableProductsToCart": {
      "cart": {
        "items": [
          {
            "id": "1",
            "quantity": 3,
            "product": {
              "sku": "Configurable Product 1"
            },
            "configurable_options": [
              {
                "option_label": "Dynamic Attribute ca_1_631447041",
                "value_label": "option 1"
              },
              {
                "option_label": "Dynamic Attribute ca_2_631447041",
                "value_label": "option 1"
              }
            ]
          }
        ]
      }
    }
  }
}
@m2-community-project m2-community-project bot added this to Ready for Grooming in Backlog Aug 24, 2019
@pmclain pmclain self-assigned this Aug 24, 2019
@m2-community-project m2-community-project bot moved this from Ready for Grooming to Dev In Progress in Backlog Aug 24, 2019
@pmclain
Copy link
Contributor Author

pmclain commented Aug 24, 2019

This is only reproducible when adding multiple variants of the same configurable SKU. This works as expected when the configurable SKUs are different.

pmclain added a commit to pmclain/graphql-ce that referenced this issue Aug 24, 2019
This prevents undesired behavior when adding multiple variants of the same SKU
to the cart in a single request. Without cloning the product when adding to,
the product object set with the quote item is a referenced object. When adding
a n+1 cart item with same sku, but different options multiple cart items are
referencing the same instance of a product object. This causes
Item::representProduct to ignore custom option and variant differences.

Fixes magento#854
@m2-community-project m2-community-project bot moved this from Dev In Progress to Pull Request In Progress in Backlog Aug 24, 2019
@TomashKhamlai
Copy link
Contributor

TomashKhamlai commented Aug 27, 2019

@lenaorobei, not a bug, I believe. On Storefront the dropdown menu is not of the type "multiple" it is an ordinary select menu. Customer is able to select more than 1 variation but in this case, Customer has to add the product to the cart twice.

@m2-community-project m2-community-project bot moved this from Pull Request In Progress to Done in Backlog Aug 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Backlog
  
Done
Development

No branches or pull requests

2 participants