Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create cron job without admin panel in Prestashop

I'm trying create simple new cron job for my module in Prestashop. Everywhere I see to do it I must define my cron in admin panel. But it seems stupid, because I won't write to each person which download my module to activate this cron manually. I wrote cron jobs for wordpress and magento without problem, but in Prestashop I can't find any tutorial when would be described this process. It is possible to write and activate cron automatically?

Thanks

like image 1000
Kyniu Avatar asked Nov 16 '25 08:11

Kyniu


1 Answers

The following applies to Prestashop's "native" cronjob handler (version 1.3.2)

You can make your module auto-install a cronjob by ensuring the following:

  1. Register to the hook actionCronJob
  2. Provide a public method getCronFrequency()
  3. Provide a public method actionCronJob()

getCronFrequency should return an array that looks like this:

array('hour'=>1, 'day'=>-1, 'month'=>-1, 'day_of_week'=>1);

The -1 values are the equivalent of the * in Unix-style cronjobs.

Be aware though, that "Basic" mode cron jobs get triggered by a webservice hosted by Prestashop themselves. This means your website has to be publicly accessible so you can't easily test this on your typical localhost development environment.

Advanced cronjobs are not registered at Prestashop's webservice, so you can trigger them yourself through your own crontab manager.

like image 179
Menno Bieringa Avatar answered Nov 18 '25 17:11

Menno Bieringa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!