18 votes
Accepted

Magento 2 : Updating quote item

I am not sure about my below solution: May be you need to load Quote item object by item id As you want set price then using setPrice() you cannot set your desire price for that cart item $item = $...
Amit Bera's user avatar
  • 77.4k
12 votes

Magento 2 : Get Quote Item Selected Options

You can usually call $item->getProductOptions() to get all options and then sort through to get selected options as mentioned by @Rakesh Jesadiya. But, Sometimes $item->getProductOptions() ...
Vivek Kumar's user avatar
  • 5,105
11 votes
Accepted

How to check if cart is empty in observer Magento 2

You can also use the cart helper protected $cartHelper; public function __construct( \Magento\Checkout\Helper\Cart $cartHelper ) { $this->cartHelper = $cartHelper; }...
Nikolas's user avatar
  • 2,281
11 votes
Accepted

Get quote item collection by using quote item id in Magento 2

private $quoteItemFactory; private $itemResourceModel; public function __construct( ..... \Magento\Quote\Model\Quote\ItemFactory $quoteItemFactory, \Magento\Quote\Model\ResourceModel\Quote\Item $...
Marius's user avatar
  • 198k
8 votes

Magento 2 Custom remove item from cart button

You can simply use in app/design/frontend/Vendor/Themename/Magento_Checkout/templates/cart/item/default.phtml below code. <a href="#" title="<?= $block->escapeHtml(__('Remove item'...
Ansar Husain's user avatar
  • 3,409
6 votes
Accepted

Unable to Update a quote item programmatically

Instead of direct call of sales/quote_item model,use checkout/cart singleton model (Mage::getSingleton('checkout/cart')) and it will resolve your issue. try below code: $cart=Mage::getSingleton('...
Amit Bera's user avatar
  • 77.4k
6 votes

Magento2 - Copy quote fields to order fields

On 2.1.3 at least, doing it through fieldset.xml does not work. I had to use the event sales_model_service_quote_submit_before , which is fired in function submitQuote of Magento\Quote\Model\...
Pol Ravalitera's user avatar
6 votes

Magento 2 : Get Quote Item Selected Options

If you want to know how to do something, it's always best to look at how Magento does it. So if you take a look at the cart templates, you'll notice that the template responsible for rendering a ...
Giel Berkers's user avatar
  • 12.2k
6 votes
Accepted

Add product to cart programmatically invalid request for adding product to quote

$cart = Mage::getSingleton('checkout/cart'); $cart->init(); $options = array('92'=>'49','144'=>'21'); $product = Mage::getModel('catalog/product')->load(146); $paramater = array('product' ...
Sunil Patel's user avatar
  • 2,087
6 votes

How to add custom option in quote or order item

You can achieve by a plugin in Magento 2.2.* First of all, we need to create an observer file and one Magento event file to implement this functionality. <?xml version="1.0"?> <config ...
shah dhairya's user avatar
6 votes

Quote item price changes

You can update cart item price using customer login observer. While customer login the cart item will updated with new price. app/code/Vendor/Customer/etc/frontend/events.xml <?xml version="1.0"?&...
Iyappan Perumal's user avatar
5 votes

$quote->setHasErrors(true); not working

As you probably saw on my answer for Quote/QuoteItem addErrorInfo is not persistent. The setHasError in Magento behaves like a success/failure session message. This means once the message has been ...
Alvin Nguyen's user avatar
5 votes

How To Add Additional Options In Magento 2 Cart

after $item->addOption(...) try calling $item->saveItemOptions(). Also a side note, don't add the options as serialized using serialize($additionalOptions), use json_encode or better yet the ...
Marius's user avatar
  • 198k
5 votes

Quote item price changes

First create a module using free module creator tool called silk software Magento 2 Module Creator Tool Using Silk Software and enable using following commands below. 1. php bin/magento module:...
Nagaraju Kasa's user avatar
5 votes
Accepted

How to clear item in cart in frontend web page programmatically?

You can delete cart items using below code. public function deleteQuoteItems() { $checkoutSession = $this->getCheckoutSession(); $allItems = $checkoutSession->getQuote()->...
anonymous's user avatar
  • 3,722
4 votes
Accepted

Magento2 - Copy quote fields to order fields

To copy quote item fields to sale order item fields, we need to declare these fields in fieldset.xml app/code/Vendor/Module/etc/fieldset.xml <?xml version="1.0"?> <config xmlns:xsi="http://...
Khoa TruongDinh's user avatar
4 votes
Accepted

How to get Item id after programmatically add Product to Cart?(Not in observer)

Your code can be further simplified using the quote's addProduct method: $id = 100; $qty = 2; $product = Mage::getModel('catalog/product')->load($id); $quote = Mage::getSingleton('checkout/session'...
Andrew Noble's user avatar
4 votes

collectTotals() on quote does not update configurable product item price

I have a little different type of issue with a configurable product. The total of configurable product counted double time. So I dig into code in Magento 2.2 and found that in Magento 2.2 they ...
Prince Patel's user avatar
  • 22.7k
4 votes
Accepted

Get all item in cart using quote id Magento 2

I assume you want to get that in a class. If not, you should. Let's say the class name is Vendor\Module\Model\QuoteItems. It should look like this: <?php namespace Vendor\Module\Model; ...
Marius's user avatar
  • 198k
4 votes
Accepted

Get item collection by sku Magento 2

Currently the quote item collection must be initialized with an actual quote model to work: $quoteItemCollection->setQuote($quote); This already has been reported as a bug: https://github.com/...
Fabian Schmengler's user avatar
4 votes
Accepted

get total item price in order Magento 2

You can use the below function to fetch Total Row Price including tax. $_item->getRowTotalInclTax() Also you can check sales_order_item table columns for other possible values available to fetch ...
Pankaj Pareek's user avatar
4 votes

Get quote item collection by using quote item id in Magento 2

I want to improve the accepted answer. Unfortunately the repo tied to QuoteItem model \Magento\Quote\Api\CartItemRepositoryInterface doesn't have a get() method. So, to load a quote item entity from ...
LucScu's user avatar
  • 2,322
4 votes
Accepted

getItemById($itemId) for Magento Quote Model not working as expected in Magento 2

Try to use this below code : /** * @var \Magento\Quote\Model\Quote\Item */ protected $_itemModel; public function __construct( ......... \Magento\Quote\Model\Quote\Item $itemModel ........
Rohan Hapani's user avatar
  • 17.3k
3 votes

Magento2 how to use setCustomAttribute properly

I'm not entirely sure what version you are using, but looking at the current version of Magento\Quote\Model\Quote\Item there is no function setCustomAttribute. https://github.com/magento/magento2/blob/...
Pmclain's user avatar
  • 2,588
3 votes

How to create quote and order programmatically in Magento2

Solved the issues was that i use Magento\Catalog\Model\Product instead of Magento\Catalog\Model\ProductFactory in the constructor. and so foreach became foreach($orderData['items'] as $item){ $...
itorso's user avatar
  • 141
3 votes

Quote/QuoteItem addErrorInfo is not persistent

Confirming addErrorInfo is only for a single request and not persist into session. The way Magento core handle the cart error is upon cart update and re-check before checkout progress.
Alvin Nguyen's user avatar
3 votes

Getting an item from quote object

Try Below code and let me know if it is not working $session = Mage::getSingleton('checkout/session'); foreach ($session->getQuote()->getAllItems() as $item) { print_r($item->getData()...
Murtuza Zabuawala's user avatar
3 votes

Magento 2 add multiple products to quote

It create an issue because,you have used this in your constructor protected $_product; public function __construct(\Magento\Catalog\Model\Product $_product ) { $this->_product = $...
Keyur Shah's user avatar
3 votes

Magento 2 : Updating quote item

The functionality you are asking about is already done in Magento\Checkout\Controller\Cart\UpdatePost which is executed when we update cart on cart page of magento. It runs updateItems() function of ...
Vivek Kumar's user avatar
  • 5,105
3 votes

Get quote item id after product added to cart in observer

For checkout_cart_add_product_complete event <?php namespace Vendor\Module\Observer; use Magento\Framework\Event\Observer as EventObserver; use Magento\Framework\Event\ObserverInterface; use ...
Eugene Tsai's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible