Sunday, 24 June 2012

How To Stop A Shopping Cart Rule From Applying Programmatically

Hi Guys,

Last week I got into a typical situcation which tweaking a shopping cart rule feature from one of my client. I had to stop applying a certain sale rule while customer is checking out with an order from the website. Here is how to do it.

Go to app\code\core\Mage\SalesRule\Model\Validator.php

Find the function: public function process(..

After the function finishes assigning some of the variables, magento is populating a master array named: $appliedRuleIds

Add you logic after this line:

foreach ($this->_getRules() as $rule) {
            /* @var $rule Mage_SalesRule_Model_Rule */
            if (!$this->_canProcessRule($rule, $address)) {
            if (!$rule->getActions()->validate($item)) {

There is whole lots of things that you can do here. Stuffs like, Change Shopping Cart Rule Discount value, Adding Surcharge in place of discount using Shopping Cart Rule, Implementing Client's business specific discount logic which could not be managed/created from admin -> Promotion.

Let me know if you have any query. Will be glad to help out.