I'm trying to setup a customized cart rule, so that when an item in the shopping cart has subscriptions enabled, that particular product has free shipping.

I'm new to Magento and managed to modify the rules management in the admin panel to add the "is_subscription_enable" rule by extending the conditions model.

What I haven't found yet, is where exactly does Magento processes and applies the shopping cart rules. Is it when items get added to the shopping cart? When building the checkout page? or is every rule applied individually and it modifies the product properties every time a new rules is added, modified or deleted?

What would be the best approach to achieve this task?

1 Answer 1


As the name suggests, Shopping cart rules get evaluated in / at the cart. More accurately, when the cart is saved, and the totals collector in the cart save routine is run. see Mage_Checkout_Model_Cart::save

Flow can differ slightly, depending on the rule used. Each condition has a validate method, which is used to validate the cart item(s) (or cart object in some instances) against the conditions in the rule. Generally each item is validate in succession. This is why cart rules can take a while to process large carts with many items.

If the condition that is evaluated is a collection (or combination) condition, it will iterate over all the child conditions, calling validate on each. Thus you can get loops within loops, where each item is validated against each condition, or succession of child conditions.

See: Mage_SalesRule_Model_Rule_Condition_Product_Found::validate for such an example.

The following image is a call stack of a 'product found' conditions flow up to the point of validating against the lowest level child condition, in a combination condition.

I think this flow should give you an idea of how the rules are processed.

stack trace of sales rule applying

Your best best to understand the sales rule flow, and how it ties in, is to use a debugger, placing breakpoints along the flow path, and analysing how it works as the code executes.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.