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 = $...
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() ...
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;
}...
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 $...
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'...
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('...
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\...
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 ...
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' ...
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 ...
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 ...
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 ...
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:...
5
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"?&...
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()->...
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://...
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'...
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 ...
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/...
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 ...
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 ...
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
........
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 = $...
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){
$...
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.
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()...
3
votes
Change Price of configurable quote item with observer
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) {
// ...
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/...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
quoteitem × 176magento2 × 96
quote × 74
magento-1.9 × 40
cart × 36
addtocart × 23
event-observer × 13
sales-quote × 9
cart-items × 9
product × 8
orders × 8
shopping-cart × 8
magento2.3 × 7
collection × 7
custom-options × 7
checkout × 6
sales-order × 6
magento2.2 × 5
onepage-checkout × 5
rest-api × 5
tax × 5
customer × 4
product-attribute × 4
magento-2.1 × 3
php × 3