Prestashop: $this->fetch does not work from the back office

Created on 1 Nov 2018  路  7Comments  路  Source: PrestaShop/PrestaShop

Describe the bug
$this->fetch on a module's configuration page always returns an empty string.

To Reproduce
Add a template to the views/templates/hook folder of a module. Call $this->fetch("module:{$this->name}/views/templates/hook/template.tpl'); from the module's getContent function. Contrary to $this->display(__FILE__, 'template.tpl'); it will not output anything. When you capture the output, you'll see that fetch returns an empty string. This is not consistent with the previous display function.
The same functions both work on the front office.

Screenshots
N/A

Additional information
PrestaShop version: 1.7.5, likely more affected
PHP version: 7.1

1.7.4.3 Bug CO Fixed Modules

Most helpful comment

I would recommend a backport to 1.7.4.4 as well!

I fully understand @snowycatsoftware 's comment, because this is a major problem for module/theme developers.
@snowycatsoftware recently had to revert the entire translation system in the official Mollie module because 1.7 translations can't be added properly when backwards compatibility with 1.5 and 1.6 has to be guaranteed. Right before building a major release, we had to check every single string again because it would no longer show French translations on 1.7.
Now with $this->fetch broken in a few releases, this basically renders this function useless throughout the entire 1.7 branch, because modules will no longer behave the same on every version, despite calling the same API. We would really appreciate it if you could give this a higher priority + implement regression tests to prevent this from happening in the future.

All 7 comments

Here's an example module to test.
testfetch.zip

It should display It is working!, but the configuration page stays empty:
screenshot from 2018-11-02 10-34-04

Hi @firstred,

Thanks for your report.
I manage to reproduce the issue with 1.7.4.3 / 1.7.5.0.
When I click on the "Configure" button, the configuration page is displayed & it stays empty.
The It is working! expression is not displayed.

Why was the assignment removed. Seems like you don't care about this mayor bug. This is preventing developers from using 1.7 templating system.

Hi @snowycatsoftware,

The issue is added to our bug roadmap.
It should be fixed by our developers.
Me & @marionf, we are from QA team of PrestaShop.
Thanks for your understanding!

I would recommend a backport to 1.7.4.4 as well!

I fully understand @snowycatsoftware 's comment, because this is a major problem for module/theme developers.
@snowycatsoftware recently had to revert the entire translation system in the official Mollie module because 1.7 translations can't be added properly when backwards compatibility with 1.5 and 1.6 has to be guaranteed. Right before building a major release, we had to check every single string again because it would no longer show French translations on 1.7.
Now with $this->fetch broken in a few releases, this basically renders this function useless throughout the entire 1.7 branch, because modules will no longer behave the same on every version, despite calling the same API. We would really appreciate it if you could give this a higher priority + implement regression tests to prevent this from happening in the future.

This was added in PS 1.7.1.0 with #7546.

https://github.com/PrestaShop/PrestaShop/blob/a64340287527c6b0547e80a24788059c21b3465a/classes/Smarty/SmartyResourceModule.php#L49-L54

The thing is, the original issue was dealing with a missing resource type error, which was fixed in the same PR. I guess it's purpose was to prevent front-office content to be displayed in the back office.

We can remove this check and make the feature working the same way on BO & FO, but expect to see it deployed on PS 1.7.6.0 as its behavior is not the same as the previous 1.7 and thus cannot be applied in a patch version.

That is awesome! Thanks @Quetzacoalt91

Was this page helpful?
0 / 5 - 0 ratings