Magento Forum

   
Page 1 of 2
Catalog price rules need scheduled tasks—great, so what goes in the cron job??? 
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

I have looked through about 50 posts on this and still can’t find an answer. If catalog price rules for promotions need scheduled tasks, and a crontab to be setup, then please tell me what file needs to be executed from a cron job to make this work? Seriously, all I want to do is get catalog pricing rules to work, and I know this is the sticking point.

Also, what is the difference between me setting something up in my own crontab to run, and the scheduled tasks that should be running as setup through the configuration? There appears to be a major disconnect in the knowledge base on this particular point.

If someone from the core team could answer this I would be more than happy to add the missing wiki entry under adding a cron job that is here: http://www.magentocommerce.com/wiki/how_to_setup_a_cron_job.

Thank you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

No one can offer any advice on how to do this? All I really need to know is what goes in the crontab in order to get catalog promotions to show up.

 
Magento Community Magento Community
Magento Community
Magento Community
 
chiaraweb
Guru
 
Avatar
Total Posts:  721
Joined:  2008-03-21
Aviano ~ Italy
 

I’m waiting the same answer question

 
Magento Community Magento Community
Magento Community
Magento Community
 
Big Billy
Member
 
Total Posts:  59
Joined:  2008-05-14
 

i think everyone needs the answer to this! anyone??

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Did you setup cronjob as described in wiki article and made sure that cron.php is actually invoked?

How often did you setup cron.php to be ran?

 
Magento Community Magento Community
Magento Community
Magento Community
 
chiaraweb
Guru
 
Avatar
Total Posts:  721
Joined:  2008-03-21
Aviano ~ Italy
 

Hi Moshe

I tried to run manually cron.php from browser, because I thought that this is a cronjob simulation…
is this true?

Because I’m not able to apply the catalog price rules or send email alert in this way....

I checked the xml file and all seem OK

Do you think that if I will set cronjob on the server the result can be different?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

@chiaraweb: you are correct, running cron.php from browser would simulate cronjob.

But only once.

cron.php will generate scheduled tasks, clean history and run pending tasks that are not later than 15 minutes (by default) from their scheduled time.

Catalog rule updates are configured to be ran at the beginning of every hour, so it would require you to run cron.php in your browser not earlier than 15 minutes to next hour.

Also, the schedules are generated for 20 minutes (by default) ahead, which means you will not find the schedule for catalog rule updates in db table (cron_schedule) if you ran cron.php before 20 minutes prior to next hour.

The configuration is explained in the wiki article mentioned above.

If the cron.php is setup in crontab to run every 5 minutes, there would be better chance on catching the correct time to run catalog rule updates.

See in `cron_schedule` table for currently scheduled tasks. The name of catalog rule updates job is “catalogrule_apply_all”

 
Magento Community Magento Community
Magento Community
Magento Community
 
chiaraweb
Guru
 
Avatar
Total Posts:  721
Joined:  2008-03-21
Aviano ~ Italy
 

Hi Moshe, tomorrow (when rules will not work) I will setup this job, after I will leave here the feedback.

Thanks a lot

 
Magento Community Magento Community
Magento Community
Magento Community
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

I just wanted to clarify something here, and that is that there are probably 10+ members who have linked to the wiki article at the wrong URL throughout the forums as recent as a few weeks ago. Seriously, folks, check your links! It took me over an hour to discover that there is actually a wiki article on this subject, and it exists here:

http://www.magentocommerce.com/wiki/how_to/how_to_setup_a_cron_job

I updated the broken link to point to the correct wiki article.

As far as the crontab is concerned, after actually reading the documentation, I had no problems setting it up correctly. I’m not a huge fan of the implementation, but it is what it is. I would also suggest that you double-check your memory limits, since I received an error that my memory had been exhausted after running the jobs. Although I have not tried it yet, the best solution for that problem I believe can be found here (read the last entries):

http://www.magentocommerce.com/boards/viewthread/2510/

 
Magento Community Magento Community
Magento Community
Magento Community
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

A little information on the crontab in regards to e-commerce for those curious…

A crontab is a Unix-like system (Unix/BSD/Linux) specific process that runs cron jobs at periodic intervals. Please note that Windows does not have a crontab, but instead has scheduled tasks that can be setup via the Windows Scheduled Task Wizard. You do not need IIS in order to run a scheduled task in Windows. Even if you run Apache on Windows, you still need to use a scheduled task, as they are OS specific, and not Web server specific.

In traditional e-commerce systems there are typically several cron jobs setup to run in the crontab. Most will hit a shell script (which in turn calls a class file that runs), but some just hit a script (like a .php file), which prompts the code to execute within that script. This is absolutely required for any robust e-commerce systems. Some examples of scripts that would be executed by cron jobs for an e-commerce storefront:

* Export all orders into an XML file every 15 minutes (which might be retrieved via SFTP by a third-party fulfillment provider).
* Import all products once every day, updating stock status, inventory, product attributes, etc.
* Update products in the catalog every 5 minutes with any special pricing based upon promotions setup in the admin.

Depending on the size of the system there might be 50+ cron jobs or scheduled tasks. For this reason, Magento, (and other systems) instead hit a single script (like cron.php in the root of Magento), which then runs all tasks based upon what is in the XML configuration files. This makes it easier for users who are not technically inclined, and who do not wish to deal with constantly modifying the jobs that are run in the crontab. The core can be updated, and so long as the single cron job is setup to run in the crontab, then all scripts should run appropriately.

This is why catalog price rules need scheduled tasks. After adding a pricing rule, Magento will need to constantly check all products to see if they meet the conditions, and then update the pricing. Remember though, that you do not need to wait until your task runs to see if your promotion has been correctly applied. Disable cache in Magento, save and apply your promotion, then hit cron.php via the browser at http://www.yourstoreurl.com/cron.php. As Moshe pointed out above though, you still need to setup the cron job so that it periodically hits cron.php and updates all the scheduled tasks running.

I hope this helps!

 
Magento Community Magento Community
Magento Community
Magento Community
 
chiaraweb
Guru
 
Avatar
Total Posts:  721
Joined:  2008-03-21
Aviano ~ Italy
 
Moshe - 12 August 2008 01:45 PM

@chiaraweb: you are correct, running cron.php from browser would simulate cronjob.

But only once.

cron.php will generate scheduled tasks, clean history and run pending tasks that are not later than 15 minutes (by default) from their scheduled time.

Catalog rule updates are configured to be ran at the beginning of every hour, so it would require you to run cron.php in your browser not earlier than 15 minutes to next hour.

Also, the schedules are generated for 20 minutes (by default) ahead, which means you will not find the schedule for catalog rule updates in db table (cron_schedule) if you ran cron.php before 20 minutes prior to next hour.

The configuration is explained in the wiki article mentioned above.

If the cron.php is setup in crontab to run every 5 minutes, there would be better chance on catching the correct time to run catalog rule updates.

See in `cron_schedule` table for currently scheduled tasks. The name of catalog rule updates job is “catalogrule_apply_all”

OK Moshe
I checked all and this is the situation

NEWSLETTER works! ... because the send instructions are in cron_scheduled table (attached)

but in that table… only newsletter was scheduled… no catalog discount rules exists

Cron works… this is clear but maybe I missing something else or in cron.php or in config.xml

this is cron.php

<?php
/**
 ......


 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

require 'app/Mage.php';

Mage::app('admin');

if (!
Mage::app()->isInstalled()) {
    
echo "Application is not installed yet, please complete install wizard first.";
}

// Only for urls
// Don't remove this
$_SERVER['SCRIPT_FILENAME''index.php';

try 
{
    Mage
::getConfig()->init()->loadEventObservers('crontab');
    
Mage::app()->addEventArea('crontab');
    
Mage::dispatchEvent('default');
catch (Exception $e{
    Mage
::printException($e);
}

Image Attachments
scr_newsletter.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
chiaraweb
Guru
 
Avatar
Total Posts:  721
Joined:  2008-03-21
Aviano ~ Italy
 

And this is (attached) my config.xml

At the bottom there is this code

<crontab>
        <
jobs>
            <
catalogrule_apply_all>
                <
schedule><cron_expr>45 1 * * *</cron_expr></schedule>
                <
run><model>catalogrule/observer::dailyCatalogUpdate</model></run>
            </
catalogrule_apply_all>
        </
jobs>
        <
events>
            <
catalog_product_get_final_price>
                <
observers>
                    <
catalogrule>
                        <
type>singleton</type>
                        <class>
catalogrule/observer</class>
                        <
method>processAdminFinalPrice</method>
                    </
catalogrule>
                </
observers>
            </
catalog_product_get_final_price>
        </
events>
    </
crontab>
</
config>

but why catalog rules are not then in cron_schedule table?
also mail alert for any items are registered on backend but not scheduled to send…

Thanks
Chiara

File Attachments
config.txt  (File Size: 7KB - Downloads: 306)
 
Magento Community Magento Community
Magento Community
Magento Community
 
chiaraweb
Guru
 
Avatar
Total Posts:  721
Joined:  2008-03-21
Aviano ~ Italy
 

@HAL1001

Are your catalog price rules running with cronjob in this moment?

can you check please your cron_schedule on db? and let me know if you have catalog price rules entries?

Thanks a lot

 
Magento Community Magento Community
Magento Community
Magento Community
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

I think the key is this information on the wiki:

“To execute all these configured tasks, the cron.php file located in the Magento root will need to be run periodically, for example every 5 minutes. Basically, this script will check if it needs to run any tasks, and if it needs to schedule any future tasks.”

From what I understand, regardless of whether it shows up or not in the list of scheduled tasks in the database, it is running properly. According to the wiki article, the catalog rules are run every hour. So even if you your cron job hits cron.php once every 5 minutes, it will only prompt to check if an hour has passed since the last catalog rules were updated. Also, if you have your default scheduled task settings, it will cleanup the success history every 60 minutes. That means even if the catalog rules task was listed at one point in the database, and completed successfully, you would not see it after cleanup happens.

If you are importing products and you are not seeing promotions, then I suggest you add one product manually, then create the promotion. When I apply a promotion to products after they were added manually, and clear my cache, then it applies it immediately.

 
Magento Community Magento Community
Magento Community
Magento Community
 
chiaraweb
Guru
 
Avatar
Total Posts:  721
Joined:  2008-03-21
Aviano ~ Italy
 

Hi Hal
you are right

but I have a cronjob that call cron.php every 5 minutes
My products are created new, and also the catalog rules for discounts, all is new, installation, virtual server, items, rules.

this is my cronjob

/usr/bin/php -f /var/www/vhosts/ecobabybusiness.it/httpdocs/shop/cron.php

It works because newsletter job are scheduled in database every 5 minutes

I think that maybe there is any problem in config.xml ... because it seems that catalog rules is called… but rules is not applied

If I click on apply rules ... price change! ... but not through cronjob

also price alert email is not sent!

 
Magento Community Magento Community
Magento Community
Magento Community
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

There is only one difference between your config and mine, and that is this line:

<schedule><cron_expr>0 1 * * *</cron_expr></schedule>

Everything else is the same. To be honest, I’m not sure if mine is running as it should. I have been able to get promos to show up, and my cron job is running, but I think like you, it is not updating the catalog pricing rules properly. I think mine update only when I apply the rules in the admin, and/or run the cron.php manually through the browser.

I get the sense that not many people use catalog pricing rule promotions extensively because they do not work as expected.

If you do get any progress on this though, and you are enlightened, can you please enlighten me as well smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2