Programmatically Add More Product To An Existing Quote In Magento 2

February 17, 2020 0 Comments
$productId = 12; // assign product Id
$qty = 2; // assign product quantity which you want to add
$quoteId = 10; // here give quote id

$product = $this->productRepository->getById($productId); // _productRepository is an instance of \Magento\Catalog\Api\ProductRepositoryInterface
$cartItem = $this->cartItem;  // cartItem is an instance of Magento\Quote\Api\Data\CartItemInterface

// set product sku to cart item
$cartItem->setSku($product->getSku());

// assign quote Id to cart item
$cartItem->setQuoteId($quoteId);

// set product Quantity
$cartItem->setQty($qty);

// add ptoduct to cart
$newItem = $this->itemRepository->save($cartItem); // it will save cart item and return newly added Item

Leave A Comment

To Top