0

I need to update multiple cart items quantity in Rest API.

Default Magento only have update single cart item.

Single cart update Item endpoint:

/V1/carts/mine/items/:itemId

I have tried with custom endpoint but not get update multiple items.

Multiple item custom endpoint:

localhost/magento2/rest/V1/custom/carts/mine/update/items?cartItem[0][item_id]=85411&cartItem[0][qty]=2&cartItem[0][quote_id]=25645&cartItem[1][item_id]=85412&cartItem[1][qty]=1&cartItem[1][quote_id]=25645

Params:

cartItem[0][item_id] 85411
cartItem[0][qty] 2
cartItem[0][quote_id] 25645
cartItem[1][item_id] 85412
cartItem[1][qty] 1
cartItem[1][quote_id] 25645

Method: PUT

Let me know if any have idea about to update multiple cart items in rest API.

Any help would be appreciated. Thanks.

asked May 21, 2020 at 12:16

1 Answer 1

2

call the items in the loop and load quote object and set quantity or another field.

sample code

 public function updateItems($cartId, $cartItem)
 {
 $result = $this->dataObjectFactory->create();
 $quote = $this->quoteRepository->getActive($cartId); 
 foreach ($cartItem as $itemValue) {
 $item = $this->quoteItemFactory->create()->load($itemValue['item_id']);
 $item = $quote->getItemById($itemValue['item_id']);
 $item->setQty($itemValue['qty']);
 $quoteItems[] = $item;
 } 
 $quote->setItems($quoteItems);
 $this->quoteRepository->save($quote);
 $quote->collectTotals();
 $quote->getLastAddedItem();}

Please let me know if this is helpful.

Devidas
3,3731 gold badge30 silver badges68 bronze badges
answered May 21, 2020 at 13:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.