2

I want to Update Cart Item quantity by customer quote_id in custom API. I have tried below code but it's not work with Magento 2.3

$quote = $this->quoteRepository->getActive($quoteId);
                 $quoteItem = $quote->getItemById($itemId);
                $quoteItem->setQty((double) $qty);
                $quoteItem->save();
                $this->quoteRepository->save($quote);

It's not working.

  • have you tried my answer?It's working code – Ketan Borada Nov 6 at 4:54
0

Below code is working for me

    $quote = $this->quoteRepository->getActive($cartId);

    $item = $quote->getItemById($data['item_id']);
    $item->setQty($data['qty']);

    $this->quoteRepository->save($quote);
0
public function updateCart($cartId,$itemId,$qty) {

    if($qty){
        $quote = $this->quoteFactory->create()->load($cartId); // \Magento\Quote\Model\QuoteFactory 
        $quoteItem = $quote->getItemById($itemId);
        $quoteItem->setQty($qty);
        $quoteItem->getProduct()->setIsSuperMode(true);
        $quoteItem->save();
        $quote->save();
    }
    return true;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.