Jump to content

What is the proper way to override a controller from PrestaShopBundle module on src?


Recommended Posts

Hello people,

I need to run specific action after Clear Cache action finish so I need to extend the clearCacheAction module on PrestaShopBundle\Controller\Admin\Configure\AdvancedParameters\PerformanceController, as far I know, we cant override those kind of controllers by the normal way (override folder), I read on PS devdocs that I could do an override for the path using routes.yml file on my custom module folder but after doing the step, the "Class not exists" error throws when I try to clear the cache from Admin Performance config.

Is there an example of what I'm trying to achiveve?

Thanks in advance!

Link to comment
Share on other sites

  • 4 weeks later...
On 7/13/2023 at 4:55 AM, Kogkalidis said:

For the moment I copy the genuine file in my module, make my modifications and then replace genuine <-> modified on install/uninstall. Not the best method but it works 😆

That would be a bad practice but will work for emergency cases...

As an update for this thread, I had to learn about decorating/overriding services and remapping routes to make this work in a 'good practice' way.

People just need to follow this doc to learn about.

Link to comment
Share on other sites

Yeah but unfortunately I think it is quite bad practise to rename well known procedures.
I have experimented with the decoration etc but when Override was like "add some extra stuff in the core class", nowadays Override means "get rid of the core file". 🤮

Moreover the modules section due to retro compatibility reasons have not been entirely deployed based on the new standards.

As an outcome when a class or controller has a "use ...." declaration, an override is not possible (learned it the hard way.... )

So I do respect your willingness to obey the rules but I cannot spend weeks for a simple thing.

Link to comment
Share on other sites

7 hours ago, Kogkalidis said:

Yeah but unfortunately I think it is quite bad practise to rename well known procedures.
I have experimented with the decoration etc but when Override was like "add some extra stuff in the core class", nowadays Override means "get rid of the core file". 🤮

Moreover the modules section due to retro compatibility reasons have not been entirely deployed based on the new standards.

As an outcome when a class or controller has a "use ...." declaration, an override is not possible (learned it the hard way.... )

So I do respect your willingness to obey the rules but I cannot spend weeks for a simple thing.

Currently Symfony (which is the framework used in the back-office, while front-end is handled by Smarty) allows both extending and overriding classes with those decorators/service override and routes remapping, I had that issue with classes with "use ..." but was solved creating modules with classes mapped with autoloader (just to learn about Composer to know how to generate) and extending core classes if we just need to override just one method instead the whole class, I think this is just OOP knowledge mixed with Symfony skills...

I think the hard thing is to understand the structure of config/routes.yml and config/services.yml to achieve your goal, and of course, create the habit to always review the core yml's of Prestashop to know which core service you need to extend :)

Link to comment
Share on other sites

  • 2 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...