Jump to content

Overriding A Controller


Recommended Posts

Hello

 

I am trying to develop a module in prestashop for product customization but I am stuck now on a particular point . I want to override the default ProductController to my module but I failed to find any solution for this.if anyone have any idea about this.
Please reply if you could help me in any way.

Thanks in advance.
Shikha

Link to comment
Share on other sites

Hello,

 

Here's a code example:

 

 

Filename: ProductController.php

File path: /modules/[mymodule]/override/controllers/front/ProductController.php

To be effective, the methods in this file will be automatically copied by PrestaShop when you install the module

Copied file path: [root]/override/controllers/front/ProductController.php (use this path directly if it's not about a module)

class ProductController extends ProductControllerCore 
{

  // put your override method(s) here
  //example
  public function setMedia()
  {
    //...
  }
}
Make sure to empty PrestaShop cache to make it work, or simply delete the file /config/class_index.php, that's the override caching file. Edited by Tuni-Soft (see edit history)
Link to comment
Share on other sites

I am trying to override a controller in my module. So I copied /controllers/admin/AdminPdfController.php to mymodule/override/controllers/admin/AdminPdfController.php as a test, without any change.

 

When I try to install my module I get this error message:

 

The following module(s) could not be installed properly:

  • mymodule :
        Unable to install override: Class AdminPdfControllerOverride56a152e8bb0f2 does not exist

What am I missing?

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