-
Notifications
You must be signed in to change notification settings - Fork 9.4k
magento/magento2#39873: addProductsToCart mutation doesn't work as expect with a given parent_sku #39950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.4-develop
Are you sure you want to change the base?
magento/magento2#39873: addProductsToCart mutation doesn't work as expect with a given parent_sku #39950
Conversation
… a given parent_sku - adding new ConfigurableProductPrecursor
Hi @KrasnoshchokBohdan. 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. |
… a given parent_sku - modifying ConfigurableProductPrecursor
@magento run all tests |
… a given parent_sku - Introduced comprehensive unit tests for ConfigurableProductPrecursor, covering scenarios like valid configurations, non-configurable parents, missing attributes, and missing products. Minor code adjustments were also made for improved readability and array merging in the process method.
@magento run all tests |
@magento run all tests |
@magento run all tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @KrasnoshchokBohdan,
Thanks for the collaboration!
Please look into the failed automated test, it seems they are failing due to the code changes.
Thanks
* @param ProductRepositoryInterface $productRepository | ||
*/ | ||
public function __construct( | ||
ProductRepositoryInterface $productRepository |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User readonly
here
… a given parent_sku Refactor constructor and update error message formatting Replaced manual property assignment in the constructor with a `readonly` property for `ProductRepositoryInterface` to simplify initialization. Improved code readability by adjusting the formatting of the error message array.
@engcom-Hotel Hi! I stuck with WebAPI tests, in report I see /var/www/html/dev/tests/api-functional/phpunit.xml and all my attempts with dev/tests/api-functional/phpunit_graphql.xml leads to errors |
@magento run all tests |
… a given parent_sku Refactor unused parameter in ConfigurableProductPrecursor. Renamed the parameter to align with coding standards and added a suppression for PHPMD warnings about unused parameters. This change improves code clarity and adheres to best practices.
@magento run all tests |
Hello @KrasnoshchokBohdan, By default, the file is named with the I hope this addresses your question. Thanks |
Hi! @engcom-Hotel should I rename phpunit_graphql.xml.dist to phpunit.xml? Sorry, maybe I misunderstood something, but I don't see phpunit.xml.dist in the folder |
Hello @KrasnoshchokBohdan, In order to run the graphql functional test on your local machine, please go through with the below documentation: https://developer.adobe.com/commerce/webapi/graphql/develop/functional-testing/#run-functional-tests Thanks |
@magento run all tests |
Thank you for your work on this PR. While reviewing the pull request and the associated issue, I noticed that the issue is no longer reproducible. According to the documentation, the addProductsToCart mutation now returns the child product in the response. Please find the link: https://developer.adobe.com/commerce/webapi/graphql/schema/cart/mutations/add-products/#specify-a-parent-and-a-child-sku On 2.4-develop, as per the documentation we can see the correct behaviour.
![]() ![]() I understand that your PR aims to address the inconsistent behavior observed when adding a configurable product via the storefront versus through GraphQL. However, I noticed that the changes introduced in the PR result in only parent SKUs being returned in both scenarios—storefront and GraphQL. This behavior is actually opposite to what’s documented Here. According to the documentation on the 2.4-develop branch, the addProductsToCart mutation should return the child product in the response. Responses returned on the PR branch Added Product to Cart Via GraphQL : ![]() Added Product to cart via storefront: ![]() ![]() Could you please update the PR to align with the documented behavior? Additionally, please create a new issue describing the observed behaviour and update the PR description to reference that issue. Looking forward to your response. Thanks! |
@engcom-Dash Hi! I made this pull request in order to either update it after approval of this pull request or to update the example response according to the current result. I hope we can handle this pull request and I will create a new one in the documentation. Usually pull requests for documentation can take a long time to be considered so I couldn't assume it would be merged earlier than this one, sorry |
Hello @KrasnoshchokBohdan, We have sent an Email to the Product Owner on the clarification of the expected behaviour for both mutation & query. Till then we are moving this PR on Hold. Thanks! |
Description (*)
First part -
In this issue, the author mentioned that responce from
this mutation
this expected result
this actual result
let's add a configurable product to the cart from frontend


in the "quote_item" table we have 2 items
let's try this query


and in the responce, we see only the configurable product
the reason for this is
\Magento\QuoteGraphQl\Model\Resolver\CartItemsPaginated::resolve
\Magento\Quote\Model\Quote::getAllVisibleItems
(item with sku "test simple" has parent_item_id)
so maybe it's better to change the responce example on this page instead of changing the code in \Magento\Quote\Model\Quote::getAllVisibleItems
Second part -
let's add a configurable product to the cart using the "addProductsToCart" mutation
in the responce we see only "test simple", and in "quote_item" table we have only one item

so I created ConfigurableProductPrecursor to add a configurable product to the cart along with a simple product.
Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
1.create an empty cart the official doc
2.add a product by specifying parent_sku following the official doc
Questions or comments
Contribution checklist (*)