Magento – How to check if the current shopping cart has met the conditions of a specific Shopping Cart Price Rule

cartmagento-1.9price

I have a specific shopping cart rule that checks weather 3 items or greater of products from certain categories have been added to the cart, and then gives a discount on a specific Item ( I will call it "Y" in this case).

Magento will only apply the discount on Item Y if it has been added to the cart.

What I am trying to do is display the option to add the product "Y" on the cart page (cart.phtml) if the user has not yet added it to the basket.

Best Answer

Welcome to the rabbit hole. You are going to have to deal with Mage/SalesRule and most likely the generic Mage/Rule.

However, as I've mentioned before, shopping cart rule is a very bad name. They're not shopping cart rules, they are checkout, aka Cash Register rules, as they're not evaluated in the cart but in the checkout.

If you really want to do this, you will have to duplicate the rule evaluation code from the checkout and probably alter it, because some rules (like free shipping) depend on the availability of an address object or customer group, which you can't count on. Start with Mage::getModel('salesrule/rule')->getCollection().

Personally, I would hardcode this and just check for the products in question in the cart, if this is a one time deal, but if this is common functionality for the shop, I wish you the best of luck ;-)

Edit: Assuming you have at least a rule ID, you can get conditions using Mage::getModel('salesrule/rule')->load($id)->getConditions(). The implementation is in Mage_Rule_Model_Abstract.

Related Topic