Skip to content

addProductsToCart graphql mutation ignores parent_sku for configurable products #40598

@damienwebdev

Description

@damienwebdev

Preconditions and environment

v2.4.7-p9

Steps to reproduce

When using the addProductsToCart mutation with parent_sku and a child sku (as documented here) to add a configurable product to the cart, the item is added as a SimpleCartItem instead of a ConfigurableCartItem. This results in incorrect product URLs, missing thumbnails, and missing configurable option data in the cart response.

  1. Create a configurable product (e.g. ParentItem) with a simple child variant (e.g. ParentItem-Variant).
  2. Add the product to the cart using addProductsToCart with parent_sku:
mutation {
  addProductsToCart(
    cartId: "{{cartId}}"
    cartItems: [
      {
        parent_sku: "ParentItem"
        sku: "ParentItem-Variant"
        quantity: 1
      }
    ]
  ) {
    cart {
      items {
        __typename
        product {
          name
          sku
          url_key
          thumbnail { url }
        }
        ... on ConfigurableCartItem {
          configurable_options {
            option_label
            value_label
          }
        }
      }
    }
  }
}
  1. Observe the cart response.

Expected result

The cart item should be a ConfigurableCartItem with:

  • product referencing the parent configurable product (correct url_key, thumbnail, etc.)
  • configurable_options populated with the selected variant options
  • configured_variant available for querying the selected simple product's data

Actual result

The cart item is a SimpleCartItem with:

  • product referencing the child simple product directly
  • url_key is the child's URL key (which typically has no frontend route)
  • thumbnail is a placeholder image (the child simple product often has no image assigned)
  • No configurable_options data

Additional information

There are two SuperAttributeDataProvider classes that handle resolving super_attribute data for configurable products:

Class Used by Handles parent_sku?
Magento\ConfigurableProductGraphQl\Model\Cart\BuyRequest\SuperAttributeDataProvider addConfigurableProductsToCart Yes
Magento\QuoteConfigurableOptions\Model\Cart\BuyRequest\SuperAttributeDataProvider addProductsToCart No

The newer provider (QuoteConfigurableOptions) only resolves super_attribute data from selected_options (base64-encoded UIDs). It does not read parent_sku or getParentSku() from the CartItem DTO at all, despite the CartItem class fully supporting it.

Additionally, Magento\Quote\Model\Cart\AddProductsToCart::addItemToCart loads the product by $cartItem->getSku() (line 160), which is the child SKU. Even if super_attribute were correctly resolved, Quote::addProduct() receives the child simple product, whose type instance (Simple) ignores super_attribute data entirely. The configurable type instance on the parent product is what processes super_attribute.

The QuoteConfigurableOptions SuperAttributeDataProvider should fall back to resolving super_attribute from parent_sku + child sku when selected_options does not contain configurable option data. The existing logic in ConfigurableProductGraphQl\SuperAttributeDataProvider already does this correctly.

Additionally, AddProductsToCart::addItemToCart should load the parent product (via parent_sku) instead of the child when parent_sku is present, so that the configurable type instance processes the buy request.

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: Cart & CheckoutComponent: GraphQLGraphQLIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

    Type

    No type

    Projects

    Status

    Ready for Development

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions