4

When Quote id generated in magento?

Is it generated:

  • when customer got registered
  • or when customer adds product to cart.

I have gone through many article but there is no clearance on it.

3

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;
    }
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.

  • 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. – Pratik Chheda Jun 29 '16 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/… – jafar pinjar May 10 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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