Magento Deadly Loop

October 16, 2011 § 6 Comments

In Magento, you may see this

Fatal error: Allowedmemory size of 33554432 bytes exhausted (tried to allocate 363 bytes) in....

So it means that you are in a loop, or not enough memory to run the magento.

In my case, I was customizing Magento in a great extend , such as product price calculation and shopping process. Everything is going fine when the currency stays the same, but if you switch currency you will get into a dead loop.

When touching price calculation , you always come across Quote Item Abstract class. However, I oversaw the fact that the class already get the method to get the quote, which I instead use

Mage::getModel('core/session')->getQuote();

So it ends up looping over and over again, taking me using log function to track where it is.

Question is thereforeĀ raised, why would the Mage::getModel(‘core/session’)->getQuote() will only looping when switching currency? Need to investigate.

Tagged: ,

§ 6 Responses to Magento Deadly Loop

  • Sue says:

    I’ve just struck this problem – did you find a solution?

    • nickwanhere says:

      Hi Sue,

      I did find a solution, I end up finding the dead knot and fix it.
      In general, you have to be aware of Magento Class inter-class calling.
      For example, Class A inherits Class B, Class B has a function C call to get data from its parent.
      If you custom write a code in function C to get Class B to call function C again, then it becomes dead loop.

      Sometimes it is not that obvious, you have to actually look at where the function goes
      Here is a good reference for tracking them down. docs.magentocommerce.com
      My first guess is go through the lines you modified, and when there is a class method call, dig into it, then you probably find you way.

      Good Luck

      • Sue says:

        Sorry I should have been more explicit – I faced that exact infinite loop when customising Price.php in Magento. The loop was around getAllItems as obviously when the currency is changed, the session dumps the previous held prices and recalculates everything – inherently calling my customised Price.php which includes a call to getAllItems … this is the infinite loop. I was wondering how you got around this as obviously you can’t remove the calls from within core code, so how did you get hold of the items in the cart without causing a loop?

      • nickwanhere says:

        Did you use this code in the Mage_Sales_Model_Quote_Item_Abstract Class?

        Mage::getModel('core/session')->getQuote();

        If yes, then you should replace it by calling the quote with this method

        $this->getQuote();

        As I think system will recalculate the price if you call the first code, so you end up recalculate again when you trying to calculate this product.

  • […] leads to the same problem. The exact problem has been mentioned here https://nickwan.wordpress.com/2011/10/16/magento-deadly-loop/ but I could not find a solution to […]

  • […] leads to the same problem. The exact problem has been mentioned here https://nickwan.wordpress.com/2011/10/16/magento-deadly-loop/ but I could not find a solution to […]

Leave a comment

What’s this?

You are currently reading Magento Deadly Loop at Nick Wan L.K..

meta