Skip to content

Instantly share code, notes, and snippets.

@mpaepper
Created June 8, 2015 03:31
Show Gist options
  • Save mpaepper/6168c9617630f96a8bfc to your computer and use it in GitHub Desktop.
Save mpaepper/6168c9617630f96a8bfc to your computer and use it in GitHub Desktop.
What you need to know about debugging Magento cart price rules
Sometimes you have the problem that a Magento cart price rule does not work when you enter a coupon code, although you think it should.
There are certain areas where it could fail and I will illustrate the two most important ones.
First check for the file Mage_SalesRule_Model_Validator and its protected function _canProcessRule($rule, $address).
The rule fails inside that function and this can be for many reasons which I would divide into two main categories:
a) General limitations such as a usage limit (code can only be used 5 times), customer limit (can only be used once per customer)
b) If the general limitations do not apply, the rule will fail at if (!$rule->validate($address)) so at its validate() method.
To debug this, I found that it is most useful to go to the file Mage_Rule_Model_Condition_Combine and in the function validate() enter the following code:
foreach ($this->getConditions() as $cond) {
$validated = $cond->validate($object);
// MP These lines added
$session = Mage::getSingleton('checkout/session');
if ($validated !== $true) {
$session->addError($cond->asString());
}
Now when you enter the code and the rule fails, you will see a nice error in your cart which condition failed.
Hope this helps!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment