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.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityThe 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;
}
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.