Prestashop - override function in existing preashash module

I want to modify an existing preashop module without copying it and creating a new one. I know that you can override .tpl files in preashop, but can you do the same with php classes? For example, I would like to modify the blockcart so that it can be connected on top. Since the original version does not have this hook, I need to change the install () function! I can't change the original source (that would be a bad idea, right ...). I need to override the install () function, inheriting the blockcart module. Can this be done and where can I find an example?

+8
prestashop
source share
3 answers

I use my own override for the FrontController class to display module output at arbitrary points in tpl files - this means that the module does not need to support a specific hook. It is implemented through the smarty plugin, so you can, for example, use:

{plugin module='blockcart' hook='rightColumn'} 

The above will cause the module to output what it will display if it is connected to the right column, where the tag is inserted above (which can be anywhere in any tpl file). You can “unhook” the module from the right column so that it displays only where you want to use this technique. I used it at the production site with great success.

There are a number of articles describing how this works (with the necessary code):

Prestashop 1.4 Plugins

+11
source share

In Prestashop 1.4 you can override the main classes and module templates. Today it is impossible to redefine the php module file, but we are working on it.

+3
source share

Starting with version 1.6.0.11 PrestaShop, there is a new feature that allows developers to override classes of module instances.

Override the class of module instances by expanding it To override the class of module instances, you must extend it by specifying an extended class with the same name and adding an override suffix:

 <?php if (!defined('_PS_VERSION_')) exit; class BlockUserInfoOverride extends BlockUserInfo { public function hookDisplayNav($params) { return '<div class="header_user_info"><a>Test</a></div>'; // return $this->display(__FILE__, 'nav.tpl'); } } 

Source: http://build.prestashop.com/howtos/module/how-to-override-modules/

+1
source share

All Articles