3

How to update quote item quantity programmatically in Magento 2

From Controller and which repository should i use ?

1

You can use the Quote repository \Magento\Quote\Api\CartRepositoryInterface

 $quote = $this->quoteRepository->getActive($QuoteId);
 $quoteItem = $quote->getItemById($itemId);
if (!$quoteItem) {
  continue;
}
$quoteItem->setQty((double) $qty);
$quoteItem->save();
$this->quoteRepository->save($quote);

At this case, you also need quote id also

DELETE a quote item from Quote

use Magento\Quote\Model\Quote\Item\Repository

and use deleteById($QuoteId, $itemId),method.

  • Thank you @Amit_Bera. Working Perfect can you please tell how to delete that item. $quoteItem->delete(); <- is this correct ? – Abdullah Shahid Jul 9 '18 at 9:38
  • Please check the answer, i have updated the answer – Amit Bera Jul 9 '18 at 11:45

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.