Fix add products to cart parent SKU configurable#40741
Open
mohaelmrabet wants to merge 11 commits intomagento:2.4-developfrom
Open
Fix add products to cart parent SKU configurable#40741mohaelmrabet wants to merge 11 commits intomagento:2.4-developfrom
mohaelmrabet wants to merge 11 commits intomagento:2.4-developfrom
Conversation
…rable products
Two root causes addressed:
1. QuoteConfigurableOptions\SuperAttributeDataProvider
- Add parent_sku fallback: when selected_options contain no configurable
UIDs, resolve super_attribute data from parent_sku + child sku using
ConfigurableProductGraphQl OptionCollection (mirrors the existing logic
in ConfigurableProductGraphQl\SuperAttributeDataProvider).
- Inject ProductRepositoryInterface, OptionCollection and MetadataPool.
- Add module.xml sequence dependency on Magento_ConfigurableProductGraphQl
and declare the new composer requirements.
2. Quote\Model\Cart\AddProductsToCart::addItemToCart
- When parent_sku is present, load/clone the parent configurable product
instead of the child simple product so that Quote::addProduct() invokes
the Configurable type instance, which correctly processes super_attribute.
- Pre-load parent SKUs in addItemsToCart to keep a single DB round-trip.
- Use the child product SKU only for stock quantity display.
Tests: 8 unit tests added for SuperAttributeDataProvider covering
selected_options path, parent_sku fallback, priority rules, error cases.
|
Hi @mohaelmrabet. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
Contributor
Author
|
@magento run all tests |
Contributor
Author
|
@magento run Static tests |
…-parent-sku-configurable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description (*)
addProductsToCartmutation ignoresparent_skufor configurable products, causing the item to be added without the correct variant options (wrong product type instance processes the buy request).Two root causes are fixed:
1.
QuoteConfigurableOptions\SuperAttributeDataProviderWhen
selected_optionscontains no configurable UIDs, the provider now falls back to resolvingsuper_attributedata fromparent_sku+ childskuusingConfigurableProductGraphQl\Model\Options\Collection— mirroring the existing logic inConfigurableProductGraphQl\SuperAttributeDataProvider.2.
Quote\Model\Cart\AddProductsToCart::addItemToCartWhen
parent_skuis present, the service now loads the parent configurable product and passes it toQuote::addProduct()instead of the child simple product. This ensures the Configurable type instance processes thebuyRequestwith the resolvedsuper_attributedata.Related Pull Requests
Fixed Issues (if relevant)
addProductsToCartgraphql mutation ignoresparent_skufor configurable products #40598Manual testing scenarios (*)
Prerequisites: A configurable product (e.g. SKU
MH01) with at least one child variant (e.g. SKUMH01-XS-Black).Scenario 1 —
parent_skuwithoutselected_options(main fix)createEmptyCart.addProductsToCartwith:Scenario 2 —
selected_options(regression check)addProductsToCartwith a base64-encoded configurable UID inselected_options(noparent_sku).Scenario 3 — invalid
parent_skuaddProductsToCartwith aparent_skuthat does not own the given childsku."The product ... is not a variant of ...".Questions or comments
getConfigurableProductLinks) which are loaded only when the product is fetched viaProductRepository. If the product is already in the object cache this is a no-op.Contribution checklist (*)