32
votes
Accepted
Magento 2 : How to load quote by quote id
you can inject in your class an instance of \Magento\Quote\Model\QuoteFactory.
protected $quoteFactory;
public function __construct(
...
\Magento\Quote\Model\QuoteFactory $quoteFactory,
...
- 197k
25
votes
How to get all items in cart currently?
There are several methods that work in a different way:
$items = Mage::getSingleton('checkout/cart')->getQuote()->getItemsCollection();
Returns a quote item collection with all items ...
- 65.3k
18
votes
Accepted
EE 1.14.2 / CE 1.9.2: Quote items not merged correctly on login (duplicate products in cart)
Nice wrap up of the bug above, Fabian!
For any further users who will come accross this bug, there is already a patch from Magento for this.
As an Enterprise customer, you can request/download ...
- 17.3k
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 = $...
- 76.6k
17
votes
Magento 2 : How to load quote by quote id
First you need to inject a \Magento\Quote\Model\QuoteFactory in your class constructor:
protected $_quoteFactory;
public function __construct(
...
\Magento\Quote\Model\QuoteFactory $...
16
votes
EE 1.14.2 / CE 1.9.2: Quote items not merged correctly on login (duplicate products in cart)
It turned out that this is a bug in Mage_Sales_Model_Quote_Item::compare() that was introduced in Magento CE 1.9.2 / EE 1.14.2. The method is used to compare items to decide if they are the same ...
- 65.3k
14
votes
Accepted
Difference Between Sales Quote and Sales Quote Address
/app/code/core/Mage/Sales/Model/Quote.php
is the Quote class for the quote object
/app/code/core/Mage/Sales/Model/Quote/Address.php
is the Quote Address class for any quote address objects
A ...
- 9,856
14
votes
How to adding Custom Attributes to Magento 2 Quotes and Orders
app/code/Vendor/Module/etc/catalog_attributes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:...
- 1,751
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;
}...
- 2,201
10
votes
Accepted
Magento 2 : How to Update cart after cart update event (checkout_cart_update_items_after)
I ended up using plugin
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:...
- 4,479
10
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 $...
- 197k
10
votes
Accepted
What does "setIsSuperMode" do on Quote Object in Magento 2?
Reference Link
The quote is set into super mode in
app/code/core/Mage/Adminhtml/Model/Session/Quote.php:
$this->_quote->setIsSuperMode(true);
Essentially it is a flag on the quote that this ...
- 5,961
9
votes
Copy custom data from quote to order and order item once order is placed in magento2
It appears fieldsets are no longer an option for moving custom data fields around. Not clear if this is intentional, or a side-effect of other changes.
I just ran into the same problem with payments. ...
- 12.1k
9
votes
How quotes and cart work in magento
A quote is cart object, this quote is created when the customer adds the first product to the cart and its not created when the customer is created.
A customer can have many quotes. One for each ...
- 11.5k
8
votes
Accepted
Get all abandoned carts in Magento
If you go to
Magento Admin -> Reports -> Shopping Cart -> Abandoned Carts
You will see that Magento let's you pick the date, customer email etc. filters on the quote report table to get ...
- 2,520
8
votes
Accepted
Magento 2 Rest API - How to add custom option to Cart Item?
I have working with magento2 API and below ans could be something useful for you.
Step1: First of all you need to generate an empty cart for customer. If customer is already registered then you need ...
- 2,825
8
votes
Accepted
Magento 2 : Show cart items total to header cart link
You can display cart items sub-total to header minicart link.
Add below code to minicart.phtml to display cart items total
<span data-bind="html: getCartParam('subtotal')"></span>
php ...
- 15.5k
8
votes
Accepted
Will quote be removed after order created?
When the order is placed, the quote is deactivated. The field is_active is set to 0.
There is a cron that removes all the inactive quotes that are older than X days.
The cron is sales_clean_quotes and ...
- 197k
7
votes
Converting default shipping address into a quote address
I was hunting around for this too, and it looks like the quote/address class has a routine that does what we want, called importCustomerAddress:
$quoteShippingAddress->importCustomerAddress($...
- 71
7
votes
Accepted
Update custom column data in quote table Magento 2
The easiest way to solve this is to fill in this field in the quote model and save it using the Repository:
class QuoteUpdater
{
/**
* @var \Magento\Quote\Model\QuoteRepository
*/
...
- 3,746
7
votes
Accepted
Magento 2 | Get number of items in cart
$helper = $this->helper('\Magento\Checkout\Helper\Cart');
echo $helper->getSummaryCount();
- 11.5k
6
votes
Accepted
Magento: Quote vs Cart
The cart model is an abstraction for the quote (or better: for the items in the cart) and you should use it wherever possible. Working with the quote object directly when it comes to adding, removing ...
- 65.3k
6
votes
Accepted
Quote: getOrigOrderId vs. getReservedOrderId
The Magento\Quote\Model\Quote::getReservedOrderId() method is used when Order is placed and Quote is in the process of converting to a new Order. reserved_order_id then saved as new increment_id in ...
- 1,755
6
votes
Accepted
Magento 2 - How to programmatically add a product to cart multiple times but with different options?
Somewhere in Magento 2 code is the answer :
/**
* We need to reload product in this place, because products
* with the same id may have different sets of order attributes.
*/
It means that when I ...
- 1,268
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 ...
- 361
6
votes
How to get the Quote Id from Masked Quote Id (QuoteIdMask) in magento 2
Since 2.3 version of Magento you can use the \Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface::execute(string $maskedQuoteId) to obtain a real quote id (int):
<?php
namespace Vendor\Module\...
- 15.5k
6
votes
Accepted
Magento 2 : how to convert custom quote field to order field
add the fields to both table quote and sales_order via a setup script in your module.
Then add an event in your module (see below)
<?xml version="1.0"?>
<config xmlns:xsi="http://www....
- 7,530
5
votes
Accepted
How to run a query to deactivate quotes as Magento code?
The usual Magento way would be to load the collection first, then save the attribute for each item. However, this means there are at least n+1 queries for n quotes (1x SELECT and nx UPDATE)
For your ...
- 65.3k
5
votes
Accepted
Recalculate discount after change in order
Magento doesn't support updating an order. The workflow would be to cancel one order and to create a new one.
In my case, I needed to update the prices of order items because an external system would ...
- 7,422
5
votes
Accepted
Issue with quote (wrong items_count): not possible to delete products
When you try to delete a product and observer call Mage_Sales_Model_Resource_Quote::substractProductFromQuotes
This method subtract 1 to the items_count of the quotes containing you product ... in ...
- 6,945
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
quote × 638magento2 × 271
cart × 141
magento-1.9 × 101
orders × 73
quoteitem × 73
checkout × 71
event-observer × 57
sales-order × 33
shipping × 33
addtocart × 33
magento-1 × 30
magento-2.1 × 28
customer × 24
magento-1.7 × 23
database × 21
shipping-address × 20
sales-quote × 20
rest-api × 19
shipping-methods × 19
programmatically × 17
product × 15
session × 15
sales × 15
magento2.3 × 14