Jump to content

add a new action to admin sections controller


Recommended Posts

Hi every one

I have installed v 1.6 and I've been studying the guides for about a week.

I want to know what is the procedure to add another action to existing controller in Back Office.

for example for AdminProductsController I added my class in "override\controllers\admin",

then deleted index for classes,

now what to do?

if I understand correctly I need to put my logic in every function that runs by default, and execute my code block depending on it?

like in __construct(),init(),postProcess()

what should I do?

Link to comment
Share on other sites

You only need to override functions that needs modification. For example, if you have a module that just uses the same vars etc as the basic module, but adds a function, say: public function AverageProductPrice($products); or so,


then you just override the basic module and inside you define the new function.

So as an example, you could add the file override/classes/Product.php:
class Product extends ProductCore {
* Get the average product price of the given products
  public function AverageProductPrice($products)
    ...   <add function to calculate average here>
If you need to define new vars, maybe add a table, include other files etc, you may need to modify some original functions, like:
    public function __construct() {
        parent::__construct();             <- Call the original function to do the real construct
        // then add some additional things you need to do to make things work, like:        
        require_once(_PS_MODULE_DIR_ . $this->module_name . '/classes/ExtendedClass.php');
        require_once(_PS_MODULE_DIR_ . $this->module_name . '/classes/ExtendedContentClass.php');
Hope this helps,
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...