17

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 = $quote->getItemById($item->getId()); if (!$item) { continue; } $item->setQty((double) $qty); $item->setCustomPrice($price); $item->...


10

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() returns NULL, then you can call $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct()); instead and it will return options ...


10

You can also use the cart helper protected $cartHelper; public function __construct( \Magento\Checkout\Helper\Cart $cartHelper ) { $this->cartHelper = $cartHelper; } and then you can do the check if ($this->cartHelper->getItemsCount() === 0) { //add your functionality }


10

private $quoteItemFactory; private $itemResourceModel; public function __construct( ..... \Magento\Quote\Model\Quote\ItemFactory $quoteItemFactory, \Magento\Quote\Model\ResourceModel\Quote\Item $itemResourceModel ...... ) { .... $this->quoteItemFactory = $quoteItemFactory; $this->itemResourceModel = $itemResourceModel ... } and in ...


8

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')) ?>" class="action action-delete" data-post='<?= /* @escapeNotVerified */ $this->helper('Magento\Checkout\Helper\Cart')->...


6

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('checkout/cart'); $item = $cart->getQuote()->getItemById($rowQuoteId); $item->getProduct()->setIsSuperMode(true); $item->setWalletAmount($...


6

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\QuoteManagement $order->setCustomerLastname($quote->getCustomerLastname()); $this->eventManager->dispatch( '...


6

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 default product (module-checkout/view/frontend/templates/cart/item/default.phtml) uses a method getOptionList() to get the options: <?php if ($_options = $block-&...


6

$cart = Mage::getSingleton('checkout/cart'); $cart->init(); $options = array('92'=>'49','144'=>'21'); $product = Mage::getModel('catalog/product')->load(146); $paramater = array('product' => '146', 'qty' => '1', 'form_key' => Mage::getSingleton('core/session')->getFormKey(), ...


6

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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="...


5

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 rendered out on the front-end. The item and the quote itself does not have the error any more. When loading the quote to render in the cart page, Magento ...


5

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 method Magento\Framework\Serialize\Serializer\Json::serialize.


4

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://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd"> <scope id="global"> ...


4

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')->getQuote(); //Returns the newly created quote item or an error $quoteItem = $quote->addProduct($product, $qty); //Collect totals and save the quote $...


4

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 change collect function. vendor/magento/module-quote/Model/Quote/Address/Total/Grand.php In Magento 2.1 public function collect( \Magento\Quote\Model\Quote $...


4

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:enable Tw_Cart 2. php bin/magento setup:upgrade 3. php bin/magento setup:di:compile 4. php bin/magento setup:static-content:deploy create events.xml in the ...


4

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"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <...


4

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/magento/magento2/issues/8954 Luckily, to load the collection, it's only needed to retrieve the store id, so you don't need to actually load the quote: $...


4

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 on Order Item object.


4

You can delete cart items using below code. public function deleteQuoteItems() { $checkoutSession = $this->getCheckoutSession(); $allItems = $checkoutSession->getQuote()->getAllVisibleItems(); foreach ($allItems as $item) { $itemId = $item->getItemId();//item id of particular item $quoteItem=$this->getItemModel()->load($...


4

Try to use this below code : /** * @var \Magento\Quote\Model\Quote\Item */ protected $_itemModel; public function __construct( ......... \Magento\Quote\Model\Quote\Item $itemModel ......... ) { ......... $this->_itemModel = $itemModel; ......... } public function yourFunction() { $itemId = "Quote Item ID"; $this->...


3

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()); } Or In your Foreach loop Write this $myArray[] = $item->getProduct() and try again


3

It create an issue because,you have used this in your constructor protected $_product; public function __construct(\Magento\Catalog\Model\Product $_product ) { $this->_product = $product; } Instead of this use below code constructor injection public function __construct(\Magento\Catalog\Model\ProductFactory $_product )...


3

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.


3

I figured it out myself. You need to observe the event checkout_cart_product_add_after. In the observer you need the following: public function change_price(Varient_Event_Observer $observer) { // get the quote $item = $observer->getQuoteItem(); // checks for parent item if ($item->getParentItem()) { $item = $item->...


3

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/develop/app/code/Magento/Quote/Model/Quote/Item.php I've done this in the past by adding an additional column to the quote item table for my custom data. ...


3

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 Magento\Checkout\Model\Cart to update items in quote_item table . It take parameter in the form of array $data ['item id of product']['attribute you want to ...


3

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 Magento\Checkout\Model\Session as CheckoutSession; class CheckoutCartAddProductCompleteObserver implements ObserverInterface { private $_checkoutSession; ...


3

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; class QuoteItems { protected $quoteRepository; public function __construct( \Magento\Quote\Model\QuoteRepository $quoteRepository ) { ...


3

I suggest you use implement extension attribute for this field at here. See how to use Extension attribute. https://devdocs.magento.com/guides/v2.3/extension-dev-guide/extension_attributes/adding-attributes.html Make your field as an extension attribute of data interface Magento\Quote\Api\Data\CartItemInterface Create extension_attributes.xml at app/code/...


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