How to add new hook in PrestaShop engine – Prestashop Modification Tutorial Series

September 10th, 2009 by Ardian Yuli Seytanto Leave a reply »

This is random post under Prestashop Modification Tutorial Series. You have to already familiar with Object Oriented Programming in PHP, Smarty, module programming in PrestaShop, and able to manage MySql database either using web interface like PhpMyAdmin, or using command line in Windows command prompt / shell.

In this tutorial we’ll take a test case in http://moxelectronics.com/home/. By this time, this website is using flash and our client request to porting this flash website into PrestaShop theme.

Mox Electronics Flash Ecommerce Galery Home Page

Mox Electronics Flash Ecommerce Home Page

After designing new static html page with some image from this flash website we got this. Please note that this screen shot was taken while the project is still not yet finished.

New Statich HTML Page from Flash Webpage

New Statich HTML Page from Flash Webpage

After some step configuring this static html page in PrestaShop theme system we got this.

Mox Prestashop Glossy Theme

Mox Prestashop Glossy Theme

The problem is we need to place search box in the center of page like in the flash website. But in prestashop there are just hook home {$HOME} available in this area, which this hook only executed at index / default page. If user navigate to other page like categories, product details, etc they can’t see this search box. So we need to add new hook in this center of page to insert our search box in all available pages.

#1 Add hook variable in Header.php

Find this file in ../prestashop/header.php. We need to define new hook variable in this file so we can using this hook in all available place in new theme.

Add this line

'HOOK_CENTER' => Module::hookExec('center')

the result

$smarty->assign(array(
 'HOOK_HEADER' => Module::hookExec('header'),
 'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'),
 'HOOK_TOP' => Module::hookExec('top'),
 'HOOK_CENTER' => Module::hookExec('center'),
 'static_token' => Tools::getToken(false),
 'token' => Tools::getToken(),
 'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_,
 'content_only' => intval(Tools::getValue('content_only'))

));

Our new hook is named HOOK_CENTER, we can adding this hook into smarty file by using this format {$CENTER}. You can name this new hook by following variable naming conventions.

#2 Add new hook data in hook table

In order to PrestaShop understand that we have new hook available in smarty files, you need to insert new row in hook table.

INSERT INTO `yourdatabasename`.`ps_hook` (
`id_hook` ,
`name` ,
`title` ,
`description` ,
`position`
)
VALUES (
NULL , 'center', 'center of page, ', NULL , '1'
);

Description

`id_hook` = An auto increment value
`name` = Name of the new hook
`title` = This title is used in Modules tab in Back Office
`description` = The description of hook (optional)
`position` = Whether this hook observe the order of appearance with other module or not

#3 Add your hook into your template

We have defined our new hook in first step as HOOK_CENTER. You can add this hook by adding this code into your template files

{$CENTER}

In our test case, we need to add this code in 4 main files

  1. category.tpl
  2. product.tpl
  3. index.tpl
  4. cms.tpl

Just insert in the first line of each file. Maybe you want also add this line to clear your structure

<div class="clear"> </div>

#4 Make your module executed with this hook

Modify your blocksearch.php to executed with this new hook.

Change your install function into:

function install()
{
if (!parent::install() OR !$this->registerHook('center') OR !$this->registerHook('header'))
return false;
return true;
}

And add this new function

function hookCenter($params)
{
global $smarty;
$smarty->assign('ENT_QUOTES', ENT_QUOTES);
$smarty->assign('ajaxsearch', intval(Configuration::get('PS_SEARCH_AJAX')));
return $this->display(__FILE__, 'blocksearch-top.tpl');
}

Thanks for reading. This is final result from this tutorial, Adding New Hook in PrestaShop System.

Mox Prestashop Glossy Theme with Search Box

Mox Prestashop Glossy Theme with Search Box

This theme is made by my friends, its not mine. We just integrated this theme with Prestashop system. My friend designing this prestashop theme by adobe photoshop then conver it into static html page. My job was integrating this static html with prestashop theme system. Thus this prestashop theme is not free, I’m sorry if it’s not Free Prestashop Theme. In my next post I’ll review some free prestashop theme already out there for free. Thanks for subscribing.

Bookmark and Share

This links go to same article

prestashop hooksprestashop hookHOOK PRESTASHOPprestashop HOOK_TOPprestashop create hookprestashop ajouter hookprestashop create new hookprestashop template hookprestashop new hookprestashop add hookprestashop hookExecmodify header prestashopprestashop ???????? ????? ???ajouter hook prestashopprestashop theme tutorialprestashop change hooksadd new hook presta{$HOOK_TOP}optimise search module prestashopnew hook prestashop

Related posts:

PrestaShop Diet Program – PrestaShop Modification Tutorial Series

The need for speed Despite its technical sophistication and advanced functionality, the PrestaShop e-Commerce Solution is very light (around 6 MB not including translation files), so it’s easy to download, install, and update. PrestaShop is so lightweight and speedy, even customers with slow connection speeds will enjoy buying from you!...

Prestashop Images SEO Tips – Prestashop SEO Tutorial

This post is about How to optimize Prestashop in Search Engine Optimization (SEO) perspective by altering images naming convention. 3) How to name the images It’s been recognised within SEO generally that file names can have an impact on results. This is reflected too within search engine optimisation for images....

Setup Mysql Database – #2 DIY PrestaShop Installation Tutorial Series

This is part #2 from our PrestaShop Installation Tutorial Series. You can read our previous post Uploading PrestaShop files – DIY PrestaShop Installation Tutorial Series in Site5 web hosting. This step is merely same in other web hosting, please try it although with different screenshot. #1. Manage MySql Database #2...

Always connected with our Prestashop Info. We don't send spam. Email address:

26 comments

  1. bartoszek84 says:

    “Our new hook is named HOOK_CENTER, we can adding this hook into smarty file by using this format {$CENTER}.”

    Should be {$HOOK_CENTER} not {$CENTER} !!!

  2. Hello, I just stumbled upon your blog whilst hunting on the Internet as I’m searching for some material on engine lifts!. I think it’s a good site so I bookmarked your site and I will come back soon to allow more time for a proper read when I’m more free.

    • Ardian Yuli Seytanto says:

      Hello Fernando, thanks for your attention. After read your comment, I get new spirit to write some usefull article again.

  3. Hari says:

    Help me. I’m very new with prestashop.

    1. When I click any word in tag list or looking any word in search, the result is only number of post found. How do I change it into a linked words or even images?

    2. Category block modules in front doesn’t show any category. What’s wrong with it?

    3. How do I show pages in header?

    Thanks a lot.

    • Ardian Yuli Seytanto says:

      Hello Hari, I have replied your comment by email. thanks

    • Ardian Yuli Seytanto says:

      Hello Hari, sorry about undelivered our email reply.
      #1. Its a strange behaviour of Prestashop, do you have the screenshot ?
      #2. Check your language cookies and your categories language. Some people get this error because they just fill category name with default language, therefore if someone choose another language in front office they get a blank categories block.
      #3. Do you want to show some pages / some links to page ? Please searching for Wiznav navigation module.

  4. Hari says:

    It’s not coming yet…. Would you resend it to me. You may change @yahoo.com to @gmail.com, thanks.

    quote: Hello Hari, I have replied your comment by email. thanks

  5. Hari says:

    Thanks brother. It happens while I’m using “orange-boutique” themes. After changing to standard themes then it works. Right now I’m using the standard one. Any idea how, I prefer to use orange-boutique.

  6. I am having issues viewing this blog. It displays all funny with text displaying incorrectly. You might need to check it out.

  7. Mishael says:

    Wooohhhoo.. thankzzz a lot broouu.. this tutorial is great!.. but maybe change in the tutorial {$CENTER} by {$HOOK_CENTER}.. is confused :( … another thing, especify the ubication of the files.. example “blocksearch.php”.. this file is in [prestashop_root]/modules/blocksearch/.. Por todo lo demas esta Super.. mil gracias

  8. kevin says:

    Hi, just followed the tutorial point by point, did it twice, nothing works. It’s driving me nuts, i did exactly the same but i aint got anything appearing. I’m working locally with wamp and ps 1.2.5.0.

    Any clue where it could come from? (I know i might sound hard from you rpoint of view though).

  9. Ardian says:

    Hi, it’s likely I have to check this post again. sorry for this inconvenience, but you can follow the comments on this post to get what is another user get.

  10. Huy genial el tutorial pero no me funciono :( se pueden asignar modulos a la posicion pero estos no cargan :( thank

    • Ardian Yuli Seytanto says:

      Would you like to include the screenshot of your work ? just ensure you have followed all steps here and please read some comments before.

  11. Elmer Ulrick says:

    hey,I find out that your blog is extremely beneficial and useful and we wonder if there is really a possibility of obtaining More writing like this on your weblog. If you willing to assist us out, we can be willing to compensate you… Best wishes, Elmer Ulrick

  12. This post was mentioned on Twitter by Aerrie Gold.

  13. Kirtaw says:

    Hi Ardian,
    Thanks for this helpfull demonstration! Just want to suggest adding the new hook call into the template’s header.tpl, it may be easier :) .

    • Ardian Yuli Seytanto says:

      Hi Kirtaw,
      thanks for your tips,
      I didn’t yet know this technique, how can we do this ?

  14. Kirtaw says:

    All I did, based on your tutorial, is to open the header.tpl file wich is located into the_prestashop_directory/themes/; and added :

    {$HOOK_CENTER}

    after

    this way there’s no need to add : {$HOOK_CENTER} into

    1. category.tpl
    2. product.tpl
    3. index.tpl
    4. cms.tpl

    :)

    • Ardian Yuli Seytanto says:

      :O, off course, you can insert it in header.tpl,
      but based on this mox theme, you have to add negatif margin to leftbar.
      I just thinking how to insert this search bar template in right order,
      but, thanks for your comment. what is your web url ?

  15. Hi Ardian,

    Thanks a lot. I was looking for the ways to customize PrestaShop for integration in a website. This tutorial has put me on the right path.

  16. Free Artikle says:

    shares use a perfect web page decent Gives many thanks for the effort to help me personally

  17. hate says:

    WHERE THE F**K IS HOOK_TP???!??!

Leave a Reply