5

When i enabled query logging in magento from ADD TO CART till the cart page completes loading, it actually gave me same queries repeating 30-40 times.Not all queries but some of them so i decided to trace it by enabling

protected $_logCallStack        = true;

To my surprise the repeating queries in the query log are actually giving same trace details with small diff in some encoded chara for eg:

#9 Mage_SalesRule_Model_Rule_Condition_Product_Subselect#000000000a8f1b7500000000689133ef#->validate(&GoMage_Checkout_Model_Quote_Address#000000000a8f1bcd00000000689133ef#) called at [app/code/core/Mage/Rule/Model/Condition/Combine.php:251]

#9 Mage_SalesRule_Model_Rule_Condition_Product_Subselect#000000000a8f189300000000689133ef#->validate(&GoMage_Checkout_Model_Quote_Address#000000000a8f1bcd00000000689133ef#) called at [app/code/core/Mage/Rule/Model/Condition/Combine.php:251]

I am not understanding why the queries are repeatedly coming in my trace and why the same sequence of code is actually executing more than once and firing same queries repeatedly.

Or the tracing mechanism of magento is giving me wrong output?? Have anybody experienced this before.

  • +1 for this - upgraded to Magneto 1.14.1 and it looks like there is some kind of infinite loop problem - it's only on some products, so I'm trying to figure out what's going on. – Phil Birnie Nov 14 '14 at 15:28
  • 1
    Some extra info: this will show up as memory limit error when adding something to cart. When using New Relic it may trigger first the maximum nesting or first the memory error. Depending one settings of both. Diagnose with Xdebug in a dev environment. The setting xdebug.max_nesting_level at default (100) should be enough to show the loop. – Melvyn May 19 '15 at 16:27
23

For those using Enterprise 1.14.1 and have a sales rule with a subselection of categories, I ran into the OPs issue with an infinite loop. I'm not sure what version the OP is using, but this may be the problem.

In: Mage_SalesRule_Model_Rule_Condition_Product_Combine::validate(), there is call to check the child products if the product in play is configurable; if invalid, it will check the children:

        $valid = $children && $this->validate($children[0]);

The problem is that $this refers to Mage_SalesRule_Model_Rule_Condition_Product_Subselect. Notice in the validate method within this class, we have:

    foreach ($object->getQuote()->getAllVisibleItems() as $item) {
        if (parent::validate($item)) {
            $total += $item->getData($attr);
        }
    }

Well, that's a problem! The Visible Quote Items will be retrieved over and over and the parent method will continue to call the configurable item. This Mage_SalesRule_Model_Rule_Condition_Product_Subselect::validate will never run on the child object so we have an infinite loop and nobody will be able to add or view the cart.

To fix, I changed:

$valid = $children && $this->validate($children[0]); to $valid = $children && self::validate($children[0]);

This allows the Mage_SalesRule_Model_Rule_Condition_Product_Combine::validate method to run on the child products, as it should.

Update 11/21/2014

Magento just provided a patch for this as PATCH_SUPEE-4814_EE_1.14.1.0_v1.sh Changes are in: app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php on line 114:

From:

if (parent::validate($item)) {

To:

if (Mage_Rule_Model_Condition_Combine::validate($item)) {
  • I had this same issue and PhilB's change fixes it for me as well. I just upgraded to CE 1.9.1.0. Others may be interested in this patch as well, not sure if it was fixed in 1.9.1.0 github.com/husseycoding/cartrulefix – Brian Litzinger Dec 10 '14 at 19:19
  • Thanks this fix was perfect for CE 1.9.1.0 and EE 1.14.1--> Also this bug applies to not just rules involving categories , but also attribute sets too. Specifically Configurable Products and Shopping Cart Price Rules involving the "Product Subselection" conditions. Thanks for your helpful answer!! – MaierB Apr 18 '15 at 2:54
  • Thank you so much! Piotr now shared the official patch: gist.github.com/piotrekkaminski/54529dadb0bc01a62a2d – Simon Apr 18 '15 at 6:50
  • 1
    This problem still applies on fully patched 1.9.2.3 – xyphoid Apr 29 '16 at 2:03
  • 1
    We had a problem in CE 1.9 where a group (that had discounts) would get a 500 error when they added a configurable item to the cart. The apache log showed an out of memory error. The suggested fix solved the problem. – Kevin Sadler Sep 28 '16 at 9:10

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.