Jump to content

How to add new hook for prestashop 1.4 version


Recommended Posts

Hello,

I found on forum several article about how to add new hook to prestashop. I tried all this article step by step and there is no new hook created for my website.

I add new hook line to database later add function in FrontControler.php than add hook position in header.tpl but on admin panel I can not see any new hook which I created.

Somebody can help to me who really knows this subject ?

thanks

Link to comment
Share on other sites

I tried everything step by step but it doesn't work. Can you explain to me what is wrong in code which is bellow;
When I want to add module for this hook from admin panel I can't see my new hook in hook list.

header.tpl

{$HOOK_TOPBAR}



FrontController.php (lines 443-448)

self::$smarty->assign(array(
           'HOOK_HEADER' => Module::hookExec('header'),
           'HOOK_TOPBAR' => Module::hookExec('topbar'),              <-& here
           'HOOK_TOP' => Module::hookExec('top'),
           'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn')
       )); 



blockcurrencies.php module ( I want to add default currecy module for this hook)

    * Returns module content for header
   *
   * @param array $params Parameters
   * @return string Content
   */
   public function hookTop($params)
   {
       if (Configuration::get('PS_CATALOG_MODE'))
           return ;

       global $smarty;
       $currencies = Currency::getCurrencies();
       if (!sizeof($currencies))
           return '';
       $smarty->assign('currencies', $currencies);
       return $this->display(__FILE__, 'blockcurrencies.tpl');
   }

   public function hooktopbar($params)             <--- HERE IT WAS hookHeader
   {
       if (Configuration::get('PS_CATALOG_MODE'))
           return ;
       Tools::addCSS(($this->_path).'blockcurrencies.css', 'all');
   }
}



and I created ps_hook database new row for this hook.

What is wrong in this somebody can explain to me ?

thanks

Link to comment
Share on other sites

I can not add new hook for existing module ? I have to install new module for create new hook ?

Prestashop has very difficult template system. Really I can't understand what is hook mean in system. They could make possible to add module where you want like other cms system.

one week I am looking just create new hook. I think site will be done next year.

There is no easy way to add new hook or create custom template ?

Link to comment
Share on other sites

  • 2 months later...

Hello! The same problem. I saw many articles about this, but if one part of their information works fine - the second doesn`t. Someone can explain how to add custom hook without miles of poems, just what i must to do and in which files? Developers, please, find several minutes to reply.

Link to comment
Share on other sites

This tutorial is quite simple and you put the lines with Smarty whenever you want. For example, in FrontController you will find already done that, so you will just need to add additional array element.

 

If you are using your custom hook from module, do not forget to register it.

 

http://www.smaizys.com/prestashop/how-to-create-custom-prestashop-hook/

  • Like 1
Link to comment
Share on other sites

This tutorial is quite simple and you put the lines with Smarty whenever you want. For example, in FrontController you will find already done that, so you will just need to add additional array element.

 

If you are using your custom hook from module, do not forget to register it.

 

http://www.smaizys.com/prestashop/how-to-create-custom-prestashop-hook/

 

Thanks! it works!

Link to comment
Share on other sites

@netboard This is why I started using my "plugins" rather than having to write trivial modules just to add hooks.

 

Hooks are great for inserting business logic into the execution path (e.g. do X action after Y) but in my opinion are a very weak solution for the front-end.

 

You can read about how I handle such situations here:

 

http://www.ecartservice.net/prestashop-articles/1-4-plugins-revisited-part-1/

 

If you follow the articles I went on to allow a further extension that lets you place additional code in a "functions.php" file in the theme directory. This is handy for things like adding a Tools::AddCSS() call from within the theme to properly queue additional css (or indeed javascript) so that it benefits from the "CCC" functionality. You can also write your own smarty plugins in here and have them available in all your theme template files.

 

Paul

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...