How to change quantity of product in cart using REST API in magento 2?
How can i change quantity of product listed in cart of magento 2 using api call ? (without changing order of items)
4 Answers 4
How to change quantity of product in cart using REST API ?
http://magento.host/index.php/rest/V1/carts/mine/items/{item_id}
method : **PUT**Authorization : Bearer <customer token>
BODY
{
"cartItem": {
"sku": "MH11",
"qty": 1,
"quote_id": "3",
"product_option": {
"extension_attributes": {
"configurable_item_options": [
{
"option_id": "93",
"option_value": 58
},
{
"option_id": "141",
"option_value": 168
}
]
}
},
"extension_attributes": {}
}
}
FROM HERE WE CAN EDIT CART ITEM (Like Qty, Attribute options etc.)
-
1its adding new item to cart, not Changing QuantityPraveen Negimani– Praveen Negimani2019年06月03日 11:29:37 +00:00Commented Jun 3, 2019 at 11:29
Regarding reducing qty you have to omit the product_options whilst doing the PUT request to the endpoint (rest/V1/carts/mine/items/{item_id}):
"cartItem": { "sku": "WSH05", "qty": 5, "quote_id": "3" } }
The problem with this is that it doesn't do any error checking / handling, so you can set any amount of stock even if it isn't available:
"cartItem": { "sku": "WSH05", "qty": 101, "quote_id": "3" } }
I have created a github issue to see if this is intended behaviour or whether we should actually get an error message. (https://github.com/magento/magento2/issues/12846)
-
1
This is working for me to update (and overwrite, not increment) the quantity of an item in a guest cart via API call:
PUT V1/guest-carts/:cartId/items/:itemId
Body:
{
"cartItem": {
"item_id": :item_id,
"qty": :qty,
"quote_id": :cart_id_masked
}
}
Perhaps the way item quantities were being incremented instead of overwritten is a bug that was fixed?
If you use the POST method, with a sku instead of item_id, then the quantity if incremented, I noticed. Not not when using PUT.
-
its adding new item to cart, not Changing QuantityPraveen Negimani– Praveen Negimani2019年06月03日 11:29:15 +00:00Commented Jun 3, 2019 at 11:29
Assuming you want to change the quantity of a single item in a customer's cart, call:
POST V1/carts/mine/items
With a payload similar to
{
"cartItem": {
"item_id": 5,
"qty": 4,
"quote_id": "6"
}
}
-
1if i call this it will add 4 quantities , and i call again it will add 4 quantities. its called adding. I not only want to increase quantities. i do want to decrease also. so, what should i do for decrease quantities in the cart.Manoj– Manoj2016年11月27日 18:39:30 +00:00Commented Nov 27, 2016 at 18:39
-
1Do you find a native solution for this ?Franck Garnier– Franck Garnier2017年03月27日 14:44:15 +00:00Commented Mar 27, 2017 at 14:44
-
1Do you find a solution ?Jsparo30– Jsparo302017年04月22日 13:06:08 +00:00Commented Apr 22, 2017 at 13:06