How to update quote item quantity programmatically in Magento 2

From Controller and which repository should i use ?


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

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

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.

| improve this answer | |
  • 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
  • @AmitBera: it's not updating cart item qty in Magento 2.3 – Sangeeta Chandaliya Oct 9 '19 at 10:41
  • okay. i will check – Amit Bera Oct 9 '19 at 12:16
  • @sangeeta, Please check answer properly before edit the answer – Amit Bera Oct 9 '19 at 12:50

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.