Friday, April 5, 2013

How to add hook in PrestaShop 1.5

How to add hook in PrestaShop 1.5

Sometimes we need to add custom hook in prestashop
The process of Hook adding in FrontController.php in PrestaShop 1.5 is different from the other previous version of prestashop like PreataShop 1.4 but for database and installing module parts are still the same way as it before.

1. Open “FrontController.php” from /override/classes/controller/
Default file is looks like this

<?php
 
class FrontController extends FrontControllerCore
{
 
}
 
2. Then, add this following code from main FrontController.php
 
<?php
 
class FrontController extends FrontControllerCore
{
    public function initContent()
    {
        $this->process();
        if (!isset($this->context->cart))
                $this->context->cart = new Cart();
        if ($this->context->getMobileDevice() == false) {
            // These hooks aren't used for the mobile theme.
            // Needed hooks are called in the tpl files.
            if (!isset($this->context->cart))
                $this->context->cart = new Cart();
            $this->context->smarty->assign(array(
                /* === START: DO NOT TOUCH IT */
                'HOOK_HEADER' => Hook::exec('displayHeader'),
                'HOOK_TOP' => Hook::exec('displayTop'),
                'HOOK_LEFT_COLUMN' => ($this->display_column_left ? Hook::exec('displayLeftColumn') : ''),
                'HOOK_RIGHT_COLUMN' => ($this->display_column_right ? Hook::exec('displayRightColumn', array('cart' => $this->context->cart)) : ''),
                /* === END: DO NOT TOUCH IT */
                 
                /* === START: ADD HOOK | EXAMPLE */
                'HOOK_MY_USER' => Module::hookExec('myUser'),
                'HOOK_MY_CATEGORIES' => Module::hookExec('myCategories'),
                'HOOK_SEARCH' => Module::hookExec('mySearch')
                /* === END: ADD HOOK | EXAMPLE */
            ));
        } else {
            $this->context->smarty->assign(array(
                'HOOK_MOBILE_HEADER' => Hook::exec('displayMobileHeader'),
            ));
        }
    }
}
 
Now save he file and its done.. 



 

No comments:

Post a Comment

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off