Jump to content
kalle@makewebo

Override front controller of modules

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

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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 :)

Share this post


Link to post
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.

 

Dispatcher.zip

  • Like 5

Share this post


Link to post
Share on other sites

Hi Alex

 

Thank you for code and your contribution. Will test it out later.

 

And you should create new topic about this and also try to get this to Prestashop team on

github, would be nice to have in next versions.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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.

 

Happy to help. I did it for their own needs, I'm glad that was useful to others.

 

Best regards, Alex.

  • Like 1

Share this post


Link to post
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.

override.zip

  • Like 4

Share this post


Link to post
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.

Share this post


Link to post
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.

 

 

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

 

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More