16

I face with problem that Magento's Catalog rules daily update doesn't work. This means that there are no products price changes when catalog rule's expire date comes, so I have to press rule apply button in Admin. Cron is configured and working. It seems that catalogrule/observer::dailyCatalogUpdate method should check and apply rules automatically every day, but it doesn't (also I've tried to launch it manually). Here is Magento core code:

<!--file: app/code/core/Mage/CatalogRule/etc/config.xml-->
<crontab>
    <jobs>
        <catalogrule_apply_all>
            <schedule>
                <cron_expr>*/1 * * * *</cron_expr>
            </schedule>
            <run>
                <model>catalogrule/observer::dailyCatalogUpdate</model>
            </run>
        </catalogrule_apply_all>
    </jobs>
    ...
</crontab>

Observer:

/*file app/code/core/Mage/CatalogRule/Model/Observer.php*/
public function dailyCatalogUpdate($observer)
{
    Mage::getResourceSingleton('catalogrule/rule')->applyAllRulesForDateRange();

    return $this;
}

I had a success modifying observer method as below:

/*file app/code/core/Mage/CatalogRule/Model/Observer.php*/
public function dailyCatalogUpdate($observer)
{
    Mage::getModel('catalogrule/rule')->getResourceCollection()
                  ->walk(array(
                         Mage::getResourceSingleton('catalogrule/rule'),
                         'updateRuleProductData'
                  ));
    Mage::getResourceSingleton('catalogrule/rule')->applyAllRulesForDateRange();

    return $this;
}

This way rules are checked and applied every day and products prices are being changed if rule expire. I don't believe that it is a bug of Magento. Please, advise what is the problem that rules are not being checked and applied automatically?

2
  • Are there any errors being logged to your PHP error log or the messages column on the cron_schedule table? I'm assuming the cron is in fact being called since you indicated you'd had some success by modifying the observer method.
    – davidalger
    Jan 24, 2013 at 14:31
  • Also you can place some log calls in original observer and see if it gets called. Just to be safe on that. Jan 24, 2013 at 15:15

3 Answers 3

7

Recently I had the same problem when I was testing a new price rule for our project. And the reason of my headache was that I did not notice that every time when you create a new rule or edit some of the existing rules - you should press "Apply Rules" button to make Magento know about your rule changes.

2
  • 2
    Thank you very much. You are right: saving rule is not enough for changes. It would be great to have extra column in rules grid saying if rule was applied or not.
    – vovsky
    Jan 24, 2013 at 15:58
  • The dailyCatalogUpdate is suppose to apply rules nightly if you don't press that button. Otherwise what is the purpose of that cron?
    – Goose
    Mar 9, 2018 at 14:46
7

Making sure to hit "Apply Rules" is not always enough. I recently discovered that if cron is not set up properly, at some point in the future, the rules will not be applied.

I was unable to really nail down when the rules stopped working. In my case I had a handful of rules that are applied based on customer group (wholesale).

  1. Check the cron_schedule table. Make sure you have some entries here corresponding to catalogrule_apply_all (I think that's the process name).
  2. Set the cronjob in the CatalogRule module's config.xml file to run every minute or so (for testing) with */1.
  3. Look back at the cron_schedule table, and keep reloading it every couple of minutes. You should see new processes get added/executed automatically without ever having to manually hit your store's cron.php file.
  4. If you aren't seeing any of the processes update manually, SSH into the site as the user who owns the site's files. From a command line: crontab -e (you may be in Vim and not know what to do, I suggest google on using basic Vim commands).
  5. Set the crontab to run: */1 * * * * /path/to/your/cron.sh
  6. Now check the cron_schedule table again to make sure that cron processes are executing automatically.
  7. Hopefully, all is good at this point. Go ahead and go back and set your cron processes to run at the desired intervals.
0
3

Check if the job gets scheduled

You can do this by either checking the database or install this extension: Aoe_Scheduler

Test if the job works

Create a php script run_my_rules.php and put in there only the content for the function: dailyCatalogUpdate then run that from the console. See what is happening.

Your Answer

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

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