4

I’m working with Magento and trying to understand when the quote ID is generated. Specifically, I want to know whether it is generated when a customer gets registered or when a customer adds a product to their cart.

I’ve gone through several articles, but there is no clear explanation on this topic. Can someone shed light on when exactly the quote ID is created in Magento?

3 Answers 3

4

The quote id is generated when a product is added to cart.

Here's the workflow:

app/code/core/Magento/Checkout/controllers/CartController.php => addAction() method

$cart   = $this->_getCart();
...
$cart->save();

app/code/core/Magento/Checkout/Model/Cart.php => save() method

    $this->getQuote()->getBillingAddress();
    $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
    $this->getQuote()->collectTotals();
    $this->getQuote()->save();

app/code/core/Magento/Checkout/Model/Cart.php => getQuote() method

public function getQuote()
{
    if (!$this->hasData('quote')) {
        $this->setData('quote', $this->getCheckoutSession()->getQuote());
    }
    return $this->_getData('quote');
}

app/code/core/Magento/Checkout/Model/Session.php => getQuote() method

This is where the quote id is generated, you can see it creates a quote if the quote is null.

   if ($this->_quote === null) {
        /** @var $quote Mage_Sales_Model_Quote */
        $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore()->getId());
        if ($this->getQuoteId()) {
            if ($this->_loadInactive) {
                $quote->load($this->getQuoteId());
            } else {
                $quote->loadActive($this->getQuoteId());
            }
            if ($quote->getId()) {
                /**
                 * If current currency code of quote is not equal current currency code of store,
                 * need recalculate totals of quote. It is possible if customer use currency switcher or
                 * store switcher.
                 */
                if ($quote->getQuoteCurrencyCode() != Mage::app()->getStore()->getCurrentCurrencyCode()) {
                    $quote->setStore(Mage::app()->getStore());
                    $quote->collectTotals()->save();
                    /*
                     * We mast to create new quote object, because collectTotals()
                     * can to create links with other objects.
                     */
                    $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore()->getId());
                    $quote->load($this->getQuoteId());
                }
            } else {
                $this->setQuoteId(null);
            }
        }

        $customerSession = Mage::getSingleton('customer/session');

        if (!$this->getQuoteId()) {
            if ($customerSession->isLoggedIn() || $this->_customer) {
                $customer = ($this->_customer) ? $this->_customer : $customerSession->getCustomer();
                $quote->loadByCustomer($customer);
                $this->setQuoteId($quote->getId());
            } else {
                $quote->setIsCheckoutCart(true);
                Mage::dispatchEvent('checkout_quote_init', array('quote'=>$quote));
            }
        }

        if ($this->getQuoteId()) {
            if ($customerSession->isLoggedIn() || $this->_customer) {
                $customer = ($this->_customer) ? $this->_customer : $customerSession->getCustomer();
                $quote->setCustomer($customer);
            }
        }

        $quote->setStore(Mage::app()->getStore());
        $this->_quote = $quote;
    }
1

The quote ID in Magento is generated when a customer adds a product to their cart.

0

When you add any product in cart from site at that time quote entry is generated for you in related quote table.

main quote table is sales_flat_quote and each differnt item is store inside sales_flat_quote_item table. when customer got registered at that time no quote id is generated.

Only for product add to cart process, all product info are saved in quote table.

Thanks.

2
  • But at the time of creation of customer we get the quotation id, which you can check in same tables u told. So there is no need of adding product to cart to create quotation id. And when that customer adds product to cart the same id get used. Commented Jun 29, 2016 at 8:58
  • @Rakesh, i am adding product to cart, but i am getting quote id as empty, here is my question,magento.stackexchange.com/questions/274172/… Commented May 10, 2019 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.