community-features
community-features copied to clipboard
Magento 2 does not have a api call to add multiple product cart in a single call
Preconditions
- use api call guest-carts/27f7f91cf4344bb9bda7d30b076216f3/items
Steps to reproduce
- use api call guest-carts/27f7f91cf4344bb9bda7d30b076216f3/items
- post data sku qty
Expected result
- There should be a way to add multiple product to cartt, why this functionality is not provided.
Actual result
- Can only add 1 product in 1 call to cart
Original Report: https://github.com/magento/magento2/issues/8501 by @umang-ranium
Hello, is there any update regarding this issue? Adding multiple items to cart is a good feature to have :)
@khuenqdev the issue is opened since the long time. You need to write custom APIs for it. One API for Logged-in customer and one for guest.
@khuenqdev the issue is opened since the long time. You need to write custom APIs for it. One API for Logged-in customer and one for guest.
Yeah, it seems there's already a generic API for this kind of action that's actually update a quote with multiple items in it. The weird thing is the route actually refers to customer's cart/quote but you don't really need to login to use this API. Here's the API and sample request data:
[PUT] /V1/carts/mine
{ "quote": { "id": {{quote_id}}, "items": [ { "sku": "24-MB02", "qty": 2, "product_option": { "extension_attributes": {} }, "quote_id": {{quote_id}} }, { "sku": "24-MB04", "qty": 4, "product_option": { "extension_attributes": {} }, "quote_id": {{quote_id}} } ], "customer": { "id": 1, "email": "[email protected]", "firstname": "Veronica", "lastname": "Costello", "store_id": 1 }, "billing_address": { "firstname": "Veronica", "lastname": "Costello", "customer_id": 1, "customer_address_id": 1, "telephone": "(555) 229-3326", "country_id": "US", "postcode": "49628-7978", "region_id": 33, "region_code": "MI", "region": "Michigan", "street": [ "6146 Honey Bluff Parkway" ], "city": "Calder", "same_as_billing": 1, "save_in_address_book": 1 }, "customer_note": "", "store_id": 1, "extension_attributes": {} } }
This works!!! It's a weird one but saved me having to code up an extension...!!