Use the updateCartItems
mutation to update shopping cart items and removeItemFromCart
to remove a product from the shopping cart.
The following below steps need to follow to add products by using GraphQL in Magento 2.x
Step [1] – Recommendation to use below Simple Product syntax
Here Using Postman
Syntax –
mutation {
addSimpleProductsToCart(input: AddSimpleProductsToCartInput): {
AddSimpleProductsToCartOutput
}
}
Step [2] – Put below Request
mutation {
addSimpleProductsToCart(
input: {
cart_id: "s6Wgi4j0H2ULX0YHfD3mhOMHuAL10qLL"
cart_items: [
{
data: {
quantity: 1
sku: "24-UB02"
}
}
]
}
) {
cart {
items {
id
product {
sku
stock_status
}
quantity
}
}
}
}
Step [3] – Below output response
{
"data": {
"addSimpleProductsToCart": {
"cart": {
"items": [
{
"id": "124",
"product": {
"sku": "24-UB02",
"stock_status": "IN_STOCK"
},
"quantity": 1
}
]
}
}
}
}
Product added in quote_item database table with SKU = 24-UB02