Overriding Modules Controllers in PrestaShop 1.6

Thanks to a PrestaShop forums’ user, we can now easily extend modules’ controllers without any hardcoded modification. Let’s see how do do it!

Download Project Files

Last Week, forum user alexdee2007 posted an interesting override: it allows us to extend PrestaShop Modules’ controllers. Previously, we would have had to hardcode any modification within the originals, because the core system didn’t allow for such overrides. You can find a link to the original thread at the end of the tutorial.

What does the override do?

Its concept is very simple, yet smart. It extends the Dispatcher class’ Dispatch() method, modifying what the system looks for, once loading modules front controllers. Here is the core part:

if (file_exists(_PS_OVERRIDE_DIR_ . 'modules/' . $module_name . '/controllers/front/' . $this->controller . '.php')) {
    include_once(_PS_OVERRIDE_DIR_ . 'modules/' . $module_name . '/controllers/front/' . $this->controller . '.php');
    $controller_class = $module_name . $this->controller . 'ModuleFrontControllerOverride';
} else {

    $controller_class = $module_name . $this->controller . 'ModuleFrontController';

Basically, it looks for the existence of any file, in the override directory, with the same path and name of the original controller. If it exists, it assigns the name plus “Override” to the current class name (which is what PrestaShop does already, for modules).
This way, to extend any Module’s controller, we can simply create a file inside override/modules/*modulename*/controllers/front, named the same as the original, and then append Override to its Class name.

Video – A practical example

Additional Recources

You like the tuts and want to say "thank you"? Well, you can always feel free to donate:

  • yo_0

    Nice, very usefull

  • jollywood

    Hi Nemo,

    I tried to put this very handy override into my prestashop.
    Unfortunately smartseoplus uses the same name ( dispatcher.php ) for an override.

    What would be the best way to get both to work?


    • NemoPS

      The only way is to try to merge them manually, you have to open both files and see where the code differs and how it can be merged together (yeah, there is no easy way)

  • Alberto García Alvarez

    Whats happend if two or more modules overrides the same core module?

Store Top Sales

You like the tuts and want to say "thank you"? Well, you can always feel free to donate: