4

I am on Magento CE 1.9.0.1

I sat a Catalog Price Rule, saved and applied it, and it works correctly. Anyway, after a day it disappear. I understood the cron logic, and went to check the cron_schedule table. I have these rows

captcha_delete_expired_images
captcha_delete_expired_images
newsletter_send_all
newsletter_send_all
newsletter_send_all
newsletter_send_all
xmlconnect_notification_send_all
xmlconnect_notification_send_all
xmlconnect_notification_send_all
xmlconnect_notification_send_all

If i truncate the table and run the cron.sh script from mu ssh shell, the table gets populated again with the same rows. No CatalogRule row..

I also checked the various catalog rule tables and the rules are there..

What's (not) happening here?

Thank you!

4

you don't need to edit any of the cron files, it's not even recommended.

catalog rules do have some problems, but they can be solved directly or by adding an extra cronjob. the reason you're not seeing the cronjob in the db is because the job runs daily at 1:00 AM GMT and gets cleaned up after a few hours.

You can use n98-magerun to list your cron jobs, or http://fbrnc.net/blog/2011/03/magento-cron-scheduler#hello.

Like I said, catalog rules have some problems getting applied - most of the time they occur because of timezone issues - try changing the schedule.

Ultimately, you can create a new cronjob especially for this, but make sure you disable the default job.

Here's the file, call it catalogrule.php, put in shell/ then add a cronjob in your system executing it: php -f /full/path/to/magento/shell/catalogrule.php. You can also execute the file manually from the CLI, although that's probably not necessary.

<?php

require_once 'abstract.php';

class Mage_Shell_ApplyCatalogRules extends Mage_Shell_Abstract
{
    function run()
    {
        if ($this->getArg('h') || $this->getArg('help')) {
            die($this->usageHelp());
        }

        Mage::log('Started applying catalog rules', null, 'catalogrule.log', true);
        /** @var $resource Mage_CatalogRule_Model_Resource_Rule */
        $resource = Mage::getResourceSingleton('catalogrule/rule');
        $resource->applyAllRules();
        Mage::log('Ended applying catalog rules', null, 'catalogrule.log', true);
    }

    function usageHelp()
    {
        global $argv;
        $s = $argv[0];
        return <<<USAGE
Usage:  php -f $s
USAGE;
    }

}

$shell = new Mage_Shell_ApplyCatalogRules();
$shell->run();
  • Thanks so much for this, been struggling to get subproducts' rules applied and this fixed it! – Marlon Creative Jan 14 '16 at 9:06
2

Ok, I debugged my cron.php 2 days ago, and I found out that the var $isShellDisabled was set to false.

So it executed this block of code:

else if (!$isShellDisabled){

    $fileName = basename(__FILE__);
    $baseDir = dirname(__FILE__);
    shell_exec("/bin/sh $baseDir/cron.sh $fileName -mdefault 1 > /dev/null 2>&1 &");
    shell_exec("/bin/sh $baseDir/cron.sh $fileName -malways 1 > /dev/null 2>&1 &");
    exit;
}

After reading about someone else having the same problem, I forced $isShellDisabled to be true, so that it would skip that chunk of code and go on instead of exiting.

I also added two new lines of code, not sure if they are needed or redundant

$observ = Mage::getModel('catalogrule/observer');
$observ->dailyCatalogUpdate("0 1 * * *");

Now it's been 2 days and the catalog price rules gets correctly applied..

My cron_schedule table has still the same kind of rows, so I guess it's not designed to host CatalogRule rows?

Tip: to usefully debug cron.php I used the log method..

Mage::log( $myLogMessage, null, 'cron.log' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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