rafapas22 Posted October 31, 2016 Share Posted October 31, 2016 Hello. I am creating a custom module for import products and if execute from BO all perfect, but i like that import will be automatically, i know that for this the module must create an entry in cron of system, but, how i do this in Prestashop?? This module is for a lot of users, so that the create cron must be a method of source code, that is to be created by code when install the module in prestashop, someone can help me? Thanks Link to comment Share on other sites More sharing options...
rafapas22 Posted October 31, 2016 Author Share Posted October 31, 2016 anybody? Link to comment Share on other sites More sharing options...
El Patron Posted October 31, 2016 Share Posted October 31, 2016 (edited) There are examples in native PrestaShop modules. Currencies for example, but you should find suitable example in native ps codebase. $this->cron_url = _PS_BASE_URL_._MODULE_DIR_.'youmodulename/youmodulename-cron.php?token='.substr(Tools::encrypt('yourmodulename/cron'), 0, 10); youmodulename/youmodulename-cron.php /* * This file called using a cron to do 'something' */ include(dirname(__FILE__).'/../../config/config.inc.php'); include(dirname(__FILE__).'/../../init.php'); /* Check security token */ if (substr(Tools::encrypt('yourmodulename/cron'), 0, 10) != Tools::getValue('token') || !Module::isInstalled('youmodulename')) die('Bad token'); //v1.8 START if (!defined('_PS_MODE_DEMO_')) define('_PS_MODE_DEMO_', false); //END v1.8 include(dirname(__FILE__).'/yourmodulename.php'); $some_name = new yourmodulename(); Edited October 31, 2016 by El Patron (see edit history) 1 Link to comment Share on other sites More sharing options...
rafapas22 Posted November 2, 2016 Author Share Posted November 2, 2016 Good morning. I understand what you mean, but how and where to put the first line? in which file? reviewing the native modules prestashop all I've seen is using the module "cronjobs", I should use that module? perhaps, it is made for this? I have more questions than before .. Link to comment Share on other sites More sharing options...
El Patron Posted November 2, 2016 Share Posted November 2, 2016 Good morning. I understand what you mean, but how and where to put the first line? in which file? reviewing the native modules prestashop all I've seen is using the module "cronjobs", I should use that module? perhaps, it is made for this? I have more questions than before .. the first line is displayed in module configuration, this is copied by shop manager to add to cron. you cannot dictate what cron shop manager will use, module cron is not best choice, they may use hosting cron, you job is to create link they can copy. Link to comment Share on other sites More sharing options...
rafapas22 Posted November 3, 2016 Author Share Posted November 3, 2016 but then I can not create a cron job directly? all I can do is put a php link that the client should put in his cron? For me is more easy, but for the customer of module is more difficult... Link to comment Share on other sites More sharing options...
El Patron Posted November 3, 2016 Share Posted November 3, 2016 but then I can not create a cron job directly? all I can do is put a php link that the client should put in his cron? For me is more easy, but for the customer of module is more difficult... how would you communicate this to cron? Which cron? Please forgive if I do not understand directly who you are targeting for module...if for one shop you can code for one shop, if you code for 'unkown' shops, then one cannot make assumption they use cron module and not hosting cron. it would not be possible for generic module to add hosting cron, I suppose for module cron one could attempt a solution. Link to comment Share on other sites More sharing options...
rafapas22 Posted November 4, 2016 Author Share Posted November 4, 2016 Thanks for your response. but there must be some method to do what I want, in magento exists! , Magento for example, has a cron.php file in your root and through that file can periodically run third-party scripts, because the client only has been responsible for put in hosting the cron.php the core and not all tasks of each module of other companies. I explain? Link to comment Share on other sites More sharing options...
El Patron Posted November 4, 2016 Share Posted November 4, 2016 Yes I understand though I am not aware of any process you described for magento in prestashop. Link to comment Share on other sites More sharing options...
rocky Posted November 4, 2016 Share Posted November 4, 2016 I think you can create a function inside your module like this: public function hookActionCrobJob($params) { } When your module is installed into that hook, it will be registered in the Cron Jobs module. I've never actually tried it though and none of the core modules use it, so you'll have to investigate how it works. Maybe there's a reference to it in the PrestaShop documentation somewhere? 3 Link to comment Share on other sites More sharing options...
El Patron Posted November 4, 2016 Share Posted November 4, 2016 nice tip Rocky! Link to comment Share on other sites More sharing options...
destunk Posted January 4, 2019 Share Posted January 4, 2019 There is a tutorial about how to create a cron but it's in french. The most part of the code is in, so you can use translator to understand. It actually works well : https://www.h-hennes.fr/blog/2017/12/01/prestashop-gestion-des-taches-cron/ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now