Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DEV

Programmatically Add More Product To An Existing Quote In Magento 2

Programmatically Add More Product To An Existing Quote In Magento 2:- In this blog, I’ll explain how we can add a simple or virtual product to an existing quote.

$productId = 12; // assign product Id
$qty = 2; // assign product quantity which you want to add

//Get quote from checkout session
$session = $this->checkoutSession->create(); //checkoutSession is an instance of \Magento\Checkout\Model\SessionFactory
$quote = $session->getQuote();

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

$quote->addProduct($product, $qty);

$this->cartRepository->save($quote); //cartRepository is an instance of \Magento\Quote\Api\CartRepositoryInterface

$session->replaceQuote($quote)->unsLastRealOrderId();

For Simple Type product with custom option you can check : Programmatically Add More Product With Custom Options To An Existing Quote In Magento 2

In this way we can add simple product to an existing quote. Hope it will be helpful for you. 🙂

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home