magento2
magento2 copied to clipboard
magento/magento2#39873: addProductsToCart mutation doesn't work as expect with a given parent_sku
Description (*)
First part - In this issue, the author mentioned that responce from
this mutation
mutation {
addProductsToCart(
cartId: "LclKxxxxxxxxxxxxxxW"
cartItems: [
{
quantity: 1
parent_sku: "WSH12"
sku: "WSH12-28-Green"
}
]
) {
cart {
itemsV2 {
items {
id
product {
name
sku
}
quantity
}
total_count
page_info {
page_size
current_page
total_pages
}
}
}
user_errors {
code
message
}
}
}
this expected result
{
"data": {
"addProductsToCart": {
"cart": {
"itemsV2": {
"items": [
{
"id": "24",
"product": {
"name": "Erika Running Short",
"sku": "WSH12"
},
"quantity": 1
},
{
"id": "26",
"product": {
"name": "Erika Running Short-28-Green",
"sku": "WSH12-28-Green"
},
"quantity": 1
}
],
"total_count": 2,
"page_info": {
"page_size": 20,
"current_page": 1,
"total_pages": 1
}
}
},
"user_errors": []
}
}
}
this actual result
{
"data": {
"addProductsToCart": {
"cart": {
"itemsV2": {
"items": [
{
"id": "18",
"product": {
"name": "Erika Running Short-28-Green",
"sku": "WSH12-28-Green"
},
"quantity": 1
}
],
"total_count": 1,
"page_info": {
"page_size": 20,
"current_page": 1,
"total_pages": 1
}
}
},
"user_errors": []
}
}
}
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)
- Fixes magento/magento2#39873
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 (*)
- [ ] Pull request has a meaningful description of its purpose
- [ ] All commits are accompanied by meaningful commit messages
- [ ] All new or changed code is covered with unit/integration tests (if applicable)
- [ ] README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
- [ ] All automated tests passed successfully (all builds are green)