cancel
Showing results for 
Search instead for 
Did you mean: 

PHP timeout/max_memory error caused by quote

PHP timeout/max_memory error caused by quote

I have seen this kind of mistake made on M1 customization in 3 of the companies I worked with, so I thought it worth to share here, although I'm not sure how many are still working on M1 Smiley Tongue

 

You need to pay attention to the use of 

 

Mage::getSingleton('checkout/session')->getQuote();

when customizing cart/quote related features and make sure you don't call it before the quote is fully loaded.

 

I have seen this being called in extended Mage_Checkout_Model_Cart class or in a collect total observer, this will cause indefinite loop as Mage_Checkout_Model_Session::getQuote will call collectTotals() method if quote is not load yet

public function getQuote()
{
...

if ($this->_quote === null) {
$quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore()->getId());
...

$quote->collectTotals()->save();
...
$this->_quote = $quote;
}

I would say this is a defective design on magento but we need to avoid it ourselves.