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:

  • Alberto García Alvarez

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

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