Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prestashop - override function in existing prestashop module

Tags:

prestashop

I would like to change existing prestashop module without copying it and creating new one. I know that it is possible to override .tpl files in prestashop, but is it possible to do same thing with php classes? For instance I would like to change blockcart so that it can be hooked on top. Since original version doesnt have that hook I need to change install() function! I can`t change original source (it would be bad idea isn't it...) file I need to override install() function by inheriting blockcart module. Is it possible to do so and where I can find example?

like image 392
Ivan Milosavljevic Avatar asked May 26 '11 15:05

Ivan Milosavljevic


3 Answers

I use my own override to the FrontController class to allow the display of module output at arbitrary points in tpl files - this means that the module doesn't need to support a particular hook. It is implemented via a smarty plugin, so you can for example use:

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

The above will force the module to output what it would display if hooked to the right column where the above is tag inserted (which can be anywhere in any tpl file). You can "unhook" the module from the right column so that it only displays where you want it to using this technique. I have used it on a production site with great success.

There's a series of articles describing how it works (with the required code) available at:

Prestashop 1.4 Plugins

like image 108
Paul Campbell Avatar answered Sep 21 '22 18:09

Paul Campbell


In Prestashop 1.4 you can override core classes and module templates Today this is not possible to override a module php file but we are working on it.

like image 37
Franck Brignoli Avatar answered Sep 17 '22 18:09

Franck Brignoli


in override\modules\blockcart\blockcart.php (create it if it does not exist yet)

<?php 
    class BlockCartOverride extends BlockCart
    {
        public function hookDisplayTop($params)
        {
            return parent::hookTop($params);
        }
    }
?>

like this you can override any module to be hookable on any default or custom hook. don't forget to delete cache/class_index.php for the override to work :)

like image 22
waren0809 Avatar answered Sep 19 '22 18:09

waren0809