PrestaShop / PrestaShop

PrestaShop is the universal open-source software platform to build your e-commerce solution.
https://www.prestashop-project.org/
Other
8.23k stars 4.81k forks source link

Smarty: Unable to load template using helper generateForm from cron url #22883

Closed nthwyatt closed 3 years ago

nthwyatt commented 3 years ago

Describe the bug

Fuctioning backoffice module. When invoked from special URL to simulate activation by cron the helper function generateForm fails with:

AH01071: Got error 'PHP message: PHP Fatal error:  
Uncaught  --> Smarty: Unable to load template 'file:helpers/form/form.tpl' <-- \n  thrown in /var/www/vhosts/prestahumans.com/daryl-vault-test.prestahumans.com/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php on line 195\n'

Expected behavior

Expected to have generated HTML returned to caller.

Steps to Reproduce

  1. Install module and go to Configure.
  2. copy&paste 'Secure CRON URL' into browser and fetch.

Screenshots

If applicable, add screenshots or screen recordings to help explain your problem.

Additional information

hibatallahAouadni commented 3 years ago

Hello @nthwyatt

How did you install the module Cron tasks manager? Did you donwload it from the Github repository (link)? Please check and feedback.

Thanks!

nthwyatt commented 3 years ago

I am not using the Cron tasks manager. The URL provided by the module is used in Plesk's Schedule Tasks or in cPanel to periodically invoke the module. It can also be used in a browser to test the module.

hibatallahAouadni commented 3 years ago

Hello @nthwyatt

Well it's not our native module, I'm really sorry I can't help you :confused: Please contact your module's support team.

Or if you have questions about using third-party modules, or if you need help with your shop, please consider one of our support plans. Alternatively, you can also ask for help in the community forums or in the public Slack channel.

It seems that your issue is not a PrestaShop core bug, we will close this issue.

Thanks!

nthwyatt commented 3 years ago

The Helper functions are not Core modules?

This is not a problem with some cron task manager. This is a BackOffice module that works from the backoffice but cannot be invoked from a URL if using a Helper function like renderForm() or renderList(). I've searched the forum for solutions. No one has as worked on this. There are plenty of modules in Addons to are invoked via URLs. Like Amazzing Filter. But none of them use Helper functions to generate the HTML.

If the module example I provided it installed on PrestaShop it is easy to see this is a PrestaShop bug.

Please re-open this issue and have a look.

hibatallahAouadni commented 3 years ago

1.Install module and go to Configure.

@nthwyatt could you please provide the module name?

nthwyatt commented 3 years ago

$this->name = 'showbug'; $this->displayName = $this->l('Demostrate Helpers bug');

It is the module in the .zip file attached when this issue reported: https://github.com/PrestaShop/PrestaShop/files/5832974/v1.0.0-showbug.zip

hibatallahAouadni commented 3 years ago

Hello @nthwyatt

All right, I followed your steps and that's what I got:

https://drive.google.com/file/d/12HZzDjThD2Pd0iRWWQD_xxSJowC4VNiy/view

Please check and feedback. Thanks!

nthwyatt commented 3 years ago

Yes, you got an HTTP 500 error. In the server log will be an error like the one mentioned above: AH01071: Got error 'PHP message: PHP Fatal error:
Uncaught --> Smarty: Unable to load template 'file:helpers/form/form.tpl' <-- \n thrown in /var/www/vhosts/prestahumans.com/daryl-vault-test.prestahumans.com/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php on line 195\n'

Thjis is the problem. The includes in showbug-cron.php work fine to instantiate a backoffice class but for some reason Smarty is not being configured for use by generateForm.

hibatallahAouadni commented 3 years ago

@nthwyatt ok I will reopen it and ping the Developers team to take a deep look on it :wink: Thanks!

Ping @PrestaShop/prestashop-core-developers @PrestaShop/prestashop-maintainers could you please check this issue? Thanks in advance :relaxed:

PierreRambaud commented 3 years ago

First you're using:

$helper->token = Tools::getAdminTokenLite('AdminModules');

which require to have a customer connected, I've got an error on it.

About the form.tpl error you have two possible problems.

nthwyatt commented 3 years ago

$helper->token = Tools::getAdminTokenLite('AdminModules'); only gives an error when Debug is turned on in config/defines.inc.php I'll see if I can connect to a customer to get rid of that.

I'm not using any thing but a the default them. I'm testing this on a fresh install of PrestaShop 1.7.7.0 with no other changes. I'll try setting _PS_ADMIN_DIR_in showbug-cron.php and see if things improve. Thanks!

kpodemski commented 3 years ago

@nthwyatt

why you want to use HelperForm outside back-office context? what's the point?

nthwyatt commented 3 years ago

I'm developing a backoffice module. It is invoked by URL by a cron mechanism to email a report. The email content come from the output of a HelperList.

I used a HelperForm in the example module because it made the program shorter. A HelperList is also unable to find a template file but it is 'file:helpers/list/list_header.tpl' instead of 'file:helpers/form/form.tpl'.

nthwyatt commented 3 years ago

I had no success in setting _PS_ADMINDIR and even if I did there is no way to determine the admin dir on an exisiting site because it can be renamed for security reasons. No way to simply install the module.

Likewise I had no success in determining how to set the customer id. It is not available in the context and there seems to be no way to set it.

I see that gsitemap module uses gsitemap-cron.php to run from external trigger but sadly it does not use HelperForm so it is no help.

There is no problem running a backoffice instance using this kind of external trigger as long as it doesn't use any Helper functions.

kpodemski commented 3 years ago

You should rethink strategy of your module, using Helper in cron task is wrong choice. You should have separated method to use in both Helper and cron task. You can create one method and control output via some arguments etc.

I'm closing this ticket as this is not really a bug, we are not allowing rendering of back-office UI outside back-office.

If you want to discuss possible ways of achieving your goal in module I suggest you to create a topic on PrestaShop Stack Overflow, forum or visit us on Slack