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!

Override File

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

Need PrestaShop Modules? Have a look at my Prestashop Addons Store!

Looking for quality PrestaShop web hosting? Look no further than Arvixe Web Hosting.

Tags: , , , | Posted under PrestaShop | RSS 2.0

Author Spotlight

Fabio Porta

Fabio has been involved in web development and design since 2005, when launched his first website at the age of 16. He’s now highly skilled in both client and server side development, along with design, and since August 2012 runs a successful website about PrestaShop tutorials and Prestashop Modules called Nemo’s Post Scriptum, at http://nemops.com

Leave a Reply

Your email address will not be published. Required fields are marked *