Jump to content

Override front controller of modules


kalle@makewebo

Recommended Posts

Hi!

 

In the process of updating Prestashop so we can use module overrides. But I can't find anything about how to override a modules front controller behaviour. Is it possible and then how?

 

I have checked the documentation but sadly Prestashop documentation is just awful. Google doesn't give me anything either which is odd.

 

Best Regards

Kalle

Link to comment
Share on other sites

Thanks for taking the time. Two good guides but they don't explain what I'm asking.

 

For instance what I want to know is if there is a way to override a modules front controller. Files that are under: modules/your_module/controllers/front/my_front_controller.php.

 

In order to make it (easier) to update Prestashop and modules without having to worry about possible changes in core files.

 

A simple module override you just add "Override" at the end of your class and put the .php file in your override folder. Is it the same way with controllers of a module?

Link to comment
Share on other sites

Sorry my bad, you clearly said module front controller.

 

Not sure that possible right now. If you check these changes https://github.com/PrestaShop/PrestaShop/pull/2133/files think it is just for main module php file. And think adding Override to module front controller and placing it in right override folder would not work. Think it needs changes in core files.

Link to comment
Share on other sites

Sorry my bad, you clearly said module front controller.

 

Not sure that possible right now. If you check these changes https://github.com/PrestaShop/PrestaShop/pull/2133/files think it is just for main module php file. And think adding Override to module front controller and placing it in right override folder would not work. Think it needs changes in core files.

Yeah, seems like you are correct. That was really too bad. Maybe it's possible to cook something up by myself to get it to work. But that will have to be a project for the future.

 

Thanks so much for taking the time to help out :)

Link to comment
Share on other sites

  • 3 months later...

Put this file into override/classes/.

Then delete cache/class_index.php

This allow override front controller of modules.

 

Example:

override/modules/productscomment/controllers/front/default.php

 

class ProductCommentsDefaultModuleFrontControllerOverride extends ProductCommentsDefaultModuleFrontController {

..............

}

 

 

Tested on PS 1.6.1.4

 

 

Sorry for my bad english.

Best regards, Alex.

 

Dispatcher.zip

  • Like 5
Link to comment
Share on other sites

Put this file into override/classes/.

Then delete cache/class_index.php

This allow override front controller of modules.

 

Example:

override/modules/productscomment/controllers/front/default.php

 

class ProductCommentsDefaultModuleFrontControllerOverride extends ProductCommentsDefaultModuleFrontController {

..............

}

 

 

Tested on PS 1.6.1.4

 

 

Sorry for my bad english.

Best regards, Alex.

 

Thank you so much for this. It worked like a charm. This will make it easier to update modules. You saved a lot time for many users with this.

Link to comment
Share on other sites

Just in case. If you need override Admin Controller of modules, i have been made some changes in file Dispatcher.php.

Also you need put file AdminController.php into override/classes/controller

 

Then delete cache/class_index.php

This allow override front and admin controllers of modules.

 

Best regards, Alex.

 

Awesome! Thanks once again, it's great.

Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...

Just in case. If you need override Admin Controller of modules, i have been made some changes in file Dispatcher.php.

Also you need put file AdminController.php into override/classes/controller

 

Then delete cache/class_index.php

This allow override front and admin controllers of modules.

 

Best regards, Alex.

 

 

This doesn't work for me on PS 1.6.1.4 :(

Link to comment
Share on other sites

  • 6 months later...
En 29/2/2016 a las 8:20 PM, alexdee2007 dijo:

Just in case. If you need override Admin Controller of modules, i have been made some changes in file Dispatcher.php.

Also you need put file AdminController.php into override/classes/controller

 

Then delete cache/class_index.php

This allow override front and admin controllers of modules.

 

Best regards, Alex.

override.zip

Great, it works perfectly, even with current versions of Prestashop, thanks so much.

Edited by JavierEsK (see edit history)
  • Thanks 1
Link to comment
Share on other sites

  • 1 year later...
  • 3 months later...

My version is: 1.6.1.24

I'm trying to override this class:

mywishlist.php

class BlockWishListMyWishListModuleFrontControllerOverride extends BlockWishListMyWishListModuleFrontController
{
    public function ajaxProcessDeleteList()
  {
    die(Tools::jsonEncode(array('success' => "false")));
  }
}

 

I've used all this path but it doesn't work in any of them:

 

/override/classes/mywishlist.php

/override/classes/module/mywishlist.php

/override/classes/module/blockwishlist/mywishlist.php

/override/classes/module/blockwishlist/controllers/front/mywishlist.php

/override/modules/mywishlist.php

/override/modules/blockwishlist/mywishlist.php

/override/modules/blockwishlist/controllers/front/mywishlist.php

 

You can test it doing this 

accessing by his url:

/module/blockwishlist/mywishlist?rand=1565169640797&deleted=1&myajax=1&id_wishlist=1&action=deletelist&_=1565169634464

It should return  {"success":"false"}

 

Please, can somebody help me?

Its frustrating....

 

 

Thank you in advance !!

 

 

 

Link to comment
Share on other sites

  • 3 years later...

Still work like a charm in Prestashop 1.7.8.5 for override/modules/my_module/controllers/front

But does not work for admin, as your AdminController I put in override/classes/controller load another admin theme (new-theme instead of default).

Yet great workaround thanks.

Link to comment
Share on other sites

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...