Pete78 Posted January 23, 2020 Share Posted January 23, 2020 Hi, we used to develop some modules which have cronjobs. The file "cron.php" could look like this. <?php include('../../config/config.inc.php'); include(dirname(__FILE__).'/mymodule.php'); if (Tools::getIsset('secure_key')) { //.... //check token etc. //.... $mymodule = new mymodule(); $mymodule->doCronTask(); } In the module file, there could be methods which are calling the deprecated Tools::displayPrice(); or the newer formatPrice method of the Tool class directly. but this leads into Fatal error: Uncaught Exception: Kernel Container is not available in ***/src/Adapter/ContainerFinder.php:77 Stack trace: #0 ***/classes/Tools.php(796): PrestaShop\PrestaShop\Adapter\ContainerFinder->getContainer() #1 ***/classes/Tools.php(773): ToolsCore::getContextLocale(Object(Context)) #2 ***/classes/Tools.php(843): ToolsCore::displayPrice(166.39, Object(Currency), false) #3 ***/classes/Smarty/SmartyLazyRegister.php(83): ToolsCore::displayPriceSmarty(Array, Object(SmartyDevTemplate)) #4 ***/var/cache/dev/smarty/compile/cd/4f/cc/cd4fcc1df816cac896d5dfe8e37d88ba6a9ffd0d_0.file.invoice.tax-tab.tpl.php(94): SmartyLazyRegister->__call('displayPriceSma...', Array) #5 ***/vendor/sm in ***/src/Adapter/ContainerFinder.php on line 77 I guess, it is because no locale is defined in the context. Is there a better way to create a cron job? Do i need to load sth. before the cronjob call? This was working until displayPrice was replaced. I saw, that a couple of modules will run into this problem. Any help appreciated. Link to comment Share on other sites More sharing options...
Pete78 Posted January 23, 2020 Author Share Posted January 23, 2020 I found the answer by myself, inspired by some github search https://github.com/PrestaShop/PrestaShop/issues/15503 global $kernel; if(!$kernel){ require_once _PS_ROOT_DIR_.'/app/AppKernel.php'; $kernel = new \AppKernel('prod', false); $kernel->boot(); } needs to be called before. Link to comment Share on other sites More sharing options...
Pete78 Posted January 24, 2020 Author Share Posted January 24, 2020 And you should use a frontcrontroller to execute it, not just a plain php file... Link to comment Share on other sites More sharing options...
pierre-yves2 Posted January 26, 2020 Share Posted January 26, 2020 Hello, I want to generate pdf invoice in a cronjob and I try this directly in php require('config/config.inc.php'); global $kernel; if(!$kernel){ require_once _PS_ROOT_DIR_.'/app/AppKernel.php'; $kernel = new \AppKernel('prod', false); $kernel->boot(); } $id_order=123887; $toto= new AdminPdfController; $toto->generateInvoicePDFByIdOrder($id_order); but I have smarty error Notice: Trying to get property 'id' of non-object in classes/controller/AdminController.php on line 463 Notice: Trying to get property 'id_profile' of non-object in classes/controller/AdminController.php on line 558 Fatal error: Uncaught --> Smarty: unable to write file /dvar/cache/dev/smarty/compile/24/20/0e/wrt5e2d9ea3cee9e4_52317934 <-- thrown in vendor/smarty/smarty/libs/sysplugins/smarty_internal_runtime_writefile.php on line 60 how can I use a frontcontroller to execute it ? regards 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