Friday, 24 April 2015

How to keep applied magento catalog price rule



There is a bug in magento(it's a feature actually, not bug). Whenever we create a catalog price rule and apply this rule to our catalog products, It stops working automatically or you can say it disappears at night. Let me explain what actually happens.

When Magento displays products on frontend, it checks if there are catalog rules for this date. And the date used for this check is your local. When catalog rules are being applied, it uses GMT date. 

Now, the challenge is how to keep applied magento catalog price rule.

The best way to achieve this, is by setting cron job on your server. I will discuss this later. Actually I have got the another solution which is not the healthiest way for Magento modification, but it is the easiest one.

The problem is in Mage_CatalogRule_Model_Action_Index_Refresh::execute() function. You will have to rewrite this function/class.

Step 1:  Copy app/code/core/Mage/CatalogRule/Model/Action/Index/Refresh.php to                                                                           app/code/local/Mage/CatalogRule/Model/Action/Index/Refresh.php

Step 2:  Find execute() function. Inside the body of this function, replace line 121:
                                $timestamp = $coreDate->gmtTimestamp('Today');
                with this line:
                                $timestamp = Mage::app()->getLocale()->date(null, null, null, true)->get(Zend_Date::TIMESTAMP);

Now, you will be able to apply catalog price rule for your store products.
Enjoy e-commerce !