Open musaffar-patel opened 2 years ago
Hello @musaffar-patel
Could you please provide a custom module that implement the hookDisplayFooterProduct
hook in FO to help us reproducing the issue ASAP :pray:
Waiting for your feedback.
Thanks!
Attached ...
I’m afraid that you go wrong, the only services available in the front are doctrine related ones cf https://devdocs.prestashop.com/1.7/modules/concepts/services/
Yep, Twig is not usable in front-office yet.
That's a shame, it means half my module uses Symfony services such as routing, twig etc for the back office, while front end related must use legacy code. Nevertheless, thanks for clarifying this.
Indeed it will be better with symfony on the front, but they don’t want to migrate everything at the same time. It should have been done with the new 1.7 themes but they decided to keep smarty because they wanted to keep the modules compatibles with the old front. Smarty and twig at the same time is not possible. Be patient and it will come
You can still declare your services (and those from the core too) for the front: https://devdocs.prestashop.com/1.7/modules/concepts/services/#environments.
And I managed to use CQRS in front too, by building my own CommandBus
and injecting the necessary handlers.
But yea, for bundles like twig, it's not possible atm and I think it's even not worth to try. We have to wait. 😢
@tom-combet thanks for the suggestion. It was mainly twig and the router I was hoping to use,
Makes sense to migrate to Symfony incrementally. Will settle for using only in the BO for now.
maybe using SymfonyContainer::getInstance() to rely on the global container ? Look into FoP modules, I may have contributed an exemple...
@mickaelandrieu Thanks for the suggestion, I already attempted this and this method again only works in the back office hooks.
Another related issue I found is that, if a module uses Twig in the back office but smarty in the front office hooks, the following errors are then produced in the BO:
Warning: filemtime(): stat failed for E:\websites\prestashop\178\wwwpg\classes\PrestaShopAutoload.php(143) : eval()'d code
So it seems it's not plain sailing for modules to yet begin using Symfony code, at least the twig templating service anyway.
Chez your folder rights
Hello @musaffar-patel,
I reproduce the issue with PrestaShop version 1.7.8.6/1.7.7.8. After the module installation you provide, the error is displayed:
I'll add this to the backlog so it can be fixed.
Please be aware that some issues might take a very long time to be resolved. If this one is important to you and you cannot wait for it to be fixed on the project’s own time, we strongly suggest you consider contacting a professional to help you.
If you fix the issue on your end, please contribute it back to the project. Remember that the more people contribute, the better PrestaShop becomes for everyone.
Thank you
@sLorenzini I think it's not a real issue atm since the front migration to twig is not planned yet?
Chez your folder rights
@LouisAUTHIE it's not folder rights, folder rights are correct. This only happens when I have a front end hook using smarty and a BO hook using twig. If I remove the Front end hook which uses smarty, the twig BO hooks work again.
Hello guys, for your information Symfony is coming to the front end 😄 https://github.com/PrestaShop/PrestaShop/pull/32719
@matks This is positive news. While on the topic of Symfony, would you happen to know if it's possible to use Symfony services such as forms, grids, routes etc in the "displayAdminProductsExtra" hook (modules tab when editing a product) in the latest version of Prestashop?
@matks This is positive news. While on the topic of Symfony, would you happen to know if it's possible to use Symfony services such as forms, grids, routes etc in the "displayAdminProductsExtra" hook (modules tab when editing a product) in the latest version of Prestashop?
I did it, where are you struggling? Your module can retrieve services with get
method and Symfony is available in back-office, so you have everything to make it work.
@tom-combet I couldn't get a simple route to work under the displayAdminProductsExtra hook. Do you have a example module I could look at?
@musaffarpatel Contact me on PrestaShop Slack if you don't mind, so we don't spoil this issue thread 😉 I feel like it kinda becomes a support conversation.
@tom-combet sure, sent
Prerequisites
Describe the bug and add screenshots
When attempting to use any symfony service in a front end hook an error is generated,
For example:
generates an error:
You have requested a non-existent service "twig".
This applies to any services, such as router or custom module services. They seem to work ok in back office hooks such as
getContent()
Expected behavior
It should be possible to use symfony services as router or twig in front end hooks in the module class.
Steps to reproduce
hookDisplayFooterProduct
$router = $this->get('router');
PrestaShop version(s) where the bug happened
1.7.8.6
PHP version(s) where the bug happened
No response
If your bug is related to a module, specify its name and its version
No response