magento / community-features

Magento Features Development is an Initiative to Allows Community Memebers Join to Development of Magento Features
46 stars 18 forks source link

Magento 2 does not have a api call to add multiple product cart in a single call #31

Open magento-engcom-team opened 6 years ago

magento-engcom-team commented 6 years ago

Preconditions

  1. use api call guest-carts/27f7f91cf4344bb9bda7d30b076216f3/items

Steps to reproduce

  1. use api call guest-carts/27f7f91cf4344bb9bda7d30b076216f3/items
  2. post data sku qty

Expected result

  1. There should be a way to add multiple product to cartt, why this functionality is not provided.

Actual result

  1. Can only add 1 product in 1 call to cart

Original Report: https://github.com/magento/magento2/issues/8501 by @umang-ranium

khuenqdev commented 5 years ago

Hello, is there any update regarding this issue? Adding multiple items to cart is a good feature to have :)

mack4hack commented 5 years ago

@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 commented 5 years ago

@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": "roni_cost@example.com", "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": {} } }

studiocodeur commented 3 years ago

This works!!! It's a weird one but saved me having to code up an extension...!!