08 Sep 2019 Magento Catalog Price Rule Dissapears at Midnight
We were baffled by the problem encountered by one of our client’s Magento site.
The problem was a Catalog Price Rule keeps “resetting itself off” after midnight.
Credits for this solution posted in Stackoverflow and Alexei Yerofeyev for the genius solution.
“Yes, this is a bug in Magento (or some logic beyond my understanding). 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, so in your case GMT+5. However, when catalog rules are being applied, it uses GMT date. So that means that you aren’t able to apply rules until 5 AM.
The problem is in Mage_CatalogRule_Model_Action_Index_Refresh::execute() function. You will have to rewrite this function/class either in your extension, or via the local version of the file.”
The Fix
You have to replace line 121 here: app/code/core/Mage/CatalogRule/Model/Action/Index/Refresh.php
(Of course, following Magento’s best practice, you should not modify the core files itself; but copy Refresh.php file from the core, recreate same folder structures in local: app/local/Mage/CatalogRule/Model/Action/Index/Refresh.php)
$timestamp = $coreDate->gmtTimestamp('Today');
with this:
$timestamp = Mage::app()->getLocale()->date(null, null, null, true)->get(Zend_Date::TIMESTAMP);
After this fix, the catalog price rules should work as it should be.