Jump to content
sperio

[ SOLUTION] Create Hooks in 6 easy steps!

Recommended Posts

Took me quite a while and lots of meddling to figure this out... thought I would share with the rest of you guys on how to create a hook so u can NOT waste the number of hours like I did :)


1. Goto your database and modify ps_hook... (ps_ is what I named my database, so it can be replaced by what you named yours.)


2. find the last id_hook number and insert a new number after with the hook that you want to name e.g. I name it 'cat'


3. goto the php of the pages you want the hook to be in... e.g footer.php


4. insert 'HOOK_CAT' => Module::hookExec('cat'), into the below

$smarty->assign(array(
       'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn'),
       'HOOK_FOOTER' => Module::hookExec('footer'),
       'content_only' => intval(Tools::getValue('content_only'))));
       $smarty->display(_PS_THEME_DIR_.'footer.tpl');





5. this is the final code...

$smarty->assign(array(
       'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn'),
       'HOOK_FOOTER' => Module::hookExec('footer'),
       'HOOK_CAT' => Module::hookExec('cat'),
       'content_only' => intval(Tools::getValue('content_only'))));
       $smarty->display(_PS_THEME_DIR_.'footer.tpl');




6.insert {$HOOK_CAT} into where you want in footer.tpl and you are in business


NOTE : For the hook to appear YOU HAVE TO assign the array in the page's php... Would be good if we can have a master HOOK array list...

  • Like 6

Share this post


Link to post
Share on other sites

I want to re-position the adv block to center content area, I have followed you instruction, but got no result.
i have found in blockadvertising.php
line no 19
function install()
{
if (!parent::install())
return false;
if (!$this->registerHook('rightColumn') OR !$this->registerHook('leftColumn') OR !$this->registerHook('adv'))
return false;
return true;
}
Is there any way to display the Advertisement block in center content area below "featured products" ?? :coolsmile:

Share this post


Link to post
Share on other sites

Well, if you want to have the advertising in your home page, in the center area, you don't have to add a new Hook, because there is the 'home' hook.

You will have to change your function install() in blockadvertising with :

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



And add the function :

function hookHome($params)
   {
       return $this->hookRightColumn($params);
   }




But may I suggest you to use my module instead ? you'll be able to add and modify elements like swf files or pictures with link on it (juste like blockadvertising) in different places (like home, top, left column, right column, and footer.). You can download it >> HERE <<

And, for sperio : This is a good solution to add new Hooks, and I'm working on finding a global array. I'll make some tests soon.

Share this post


Link to post
Share on other sites

And if i want Block Specials and New Product Block in Homepage? I have tried this code to blockspecials.php but the modules page in the admin side is blank.

Share this post


Link to post
Share on other sites

DannyIDC, If your modules page in the admin side is blank, it's because you put a mistake in blockspecials.php or blocknewproducts.php.

Reset your files and try again ;)

Share this post


Link to post
Share on other sites

You've got two little mistakes :

you forgot one dollar here : (line 27)

if (!$this->registerHook('rightColumn') OR !$this->registerHook('leftColumn') OR !$this->registerHook('home'))



and a bracet at the end

   function hookHome($params)
       {
       return $this->hookRightColumn($params); 
      }

}                    << here
?>



Don't forget to comment the hook you don't want in the install function. (with the file you give me, you've got the blocspecials in the left column, AND in the right column, AND in the home.)

Don't forget also that you will not display the specials the same way in a column or in the home !! I suggest you to replace the function hookHome with a duplicate of the hookRightColumn function, and rename the .tpl returned (and create it.)

Gook Luck !!

Share this post


Link to post
Share on other sites

Thanks for the tutorial.. saved me hours

Share this post


Link to post
Share on other sites

we can help if you would provide us with the problem :)

Share this post


Link to post
Share on other sites

As I was browsing through this thread I realized you never explained how to register a module with your new custom hook. I was attempting to insert the permanent links block into a new hook below the top and I used the following code:

I replaced

if (!$this->registerHook('top'))


with

if (!$this->registerHook('top') or !$this->registerHook('upperColumn'))



AND

I inserted this function

function hookUpperColumn($params)
   {
       return $this->hookLeftColumn($params);
   }



It actually worked, but I'm not sure why. I understand that !$this->registerHook('upperColumn') would install the module in the hook with 'upperColumn' as an ID, but what is the relevance of function hookUpperColumn? I don't see the module calling it anywhere.

cheers,
Swift


EDIT: Actually I was mistaken. The module is being displayed in the center column, why?

Share this post


Link to post
Share on other sites

I am trying all I can to put the newsletter block in the center of a page. I insert a file into database named centerColumn, and I used the blocknewsletter as base, and I changed the hook from left to center. But I type www.mydomain.com/blocknewsletter.php, it has error. And I type www.mydomain.com/modules/blocknewsletter/blocknewsletter.php, it said file not find. Please help. How can I just put the newsletter block in a page in the center by itself? This is my third day at work. My boss want to put it in the page and put a coupon image on the page. Please help, otherwise I will lost my work.Please help.

Share this post


Link to post
Share on other sites

I too am trying to move the newsletter block. I want it to span 100% width below my content area, so on the top of my footer. But I seem to be having some serious problems! Any help would be greatly appreciated.

I have a feeling once I learn how to customize the blocks and call them individually designing for PrestaShop will be that much better :)

Thanks.

Share this post


Link to post
Share on other sites

Thanks for your post, it helped me create custom hooks but left out one important note:

For each module (or at least the module I needed to mod the manufactures module) you want to have appear on the hook you have to manually edit two areas:

*My custom hook is called "brand", I swapped it out for the leftColumn positions

1) The install line:

function install()
   {
       parent::install();
       $this->registerHook('brand');
       Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT', true);
       Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT_NB', 5);
       Configuration::updateValue('MANUFACTURER_DISPLAY_FORM', true);
   }



2) The params area

function hookbrand($params)
   {
       global $smarty, $link;

       $smarty->assign(array(
           'manufacturers' => Manufacturer::getManufacturers(),
           'link' => $link,
           'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
           'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
           'form_list' => Configuration::get('MANUFACTURER_DISPLAY_FORM'),
       ));
       return $this->display(__FILE__, 'blockmanufacturer.tpl');
   }



Hope this helps others who were as frustrated as I was!

  • Like 1

Share this post


Link to post
Share on other sites

I can't seem to get the hook to show up in the backend in modules>position. I've already added my hook definition in my database and also to the footer.php in the root folder. What else am I missing?

Thanks!

Share this post


Link to post
Share on other sites
Took me quite a while and lots of meddling to figure this out... thought I would share with the rest of you guys on how to create a hook so u can NOT waste the number of hours like I did :)


1. Goto your database and modify ps_hook... (ps_ is what I named my database, so it can be replaced by what you named yours.)


2. find the last id_hook number and insert a new number after with the hook that you want to name e.g. I name it 'cat'


3. goto the php of the pages you want the hook to be in... e.g footer.php


4. insert 'HOOK_CAT' => Module::hookExec('cat'), into the below

$smarty->assign(array(
       'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn'),
       'HOOK_FOOTER' => Module::hookExec('footer'),
       'content_only' => intval(Tools::getValue('content_only'))));
       $smarty->display(_PS_THEME_DIR_.'footer.tpl');





5. this is the final code...

$smarty->assign(array(
       'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn'),
       'HOOK_FOOTER' => Module::hookExec('footer'),
       'HOOK_CAT' => Module::hookExec('cat'),
       'content_only' => intval(Tools::getValue('content_only'))));
       $smarty->display(_PS_THEME_DIR_.'footer.tpl');




6.insert {$HOOK_CAT} into where you want in footer.tpl and you are in business


NOTE : For the hook to appear YOU HAVE TO assign the array in the page's php... Would be good if we can have a master HOOK array list...





I want to place the search block in the center of the page, just above the editorial module.

I followed the steps described above, but i got stuck at some point.

Here is what i did:

1. I went to the database and i defined a new hook, called search_module_center

2. As i understood from above, in my case, the new hook must be placed inside the blocksearch.php file. So i went and opened this file, and i edited the install() function. This is my new install function:
function install()
   {
       if (!parent::install() OR !$this->registerHook('top') OR !$this->registerHook('header') OR !$this->registerHook('search_module_center'))
           return false;
       return true;
   }


Notice that i added the hook by adding this piece of code: OR !$this->registerHook('search_module_center')

Now what do i do next? There's no

$smarty->assign

piece of code inside my blocksearch.php file.
Here is the point i got stuck into.

Could someone help me?
Thank you!

Share this post


Link to post
Share on other sites

You are creating hook for block search in other pages like category.tpl, products.tpl .. not in block search.
Adding OR !$this->registerHook(‘search_module_center’) means you are connecting block search and
search_module_center hook.

Steps you are missing are
goto footer.php or header.php because there are part of almost every page
and add to $smarty->assign ... part of code (step 3 and 4)

'HOOK_SEARCH_CENTER' => Module::hookExec('search_module_center'),



Then in category.tpl, products.tpl .. at beginning add

{$HOOK_SEARCH_CENTER} 



Here is another link on the subject
http://ardianys.com/64_how-to-add-new-hook-prestashop-engine-modification-tutorial-series.html

Share this post


Link to post
Share on other sites

Hi guys,

i followed the whole post and also the link razaro gave, i just cant get my new hook to work and i really need it.
Here's what i did:

- I inserted the new hook in my database.

- It worked cos i see it in my ps admin under the name "center"

- I then attached the langage and new products blocs to this hook and can see them in my admin

- I added this line

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

to the

$smarty->assign(array( ... ));

bloc in header.php (not the one from my theme, the main one).

- I created a new page top10.php with this:

<?php
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/header.php');

$smarty->display(_PS_THEME_DIR_.'top10.tpl');

include(dirname(__FILE__).'/footer.php');
?>


- And i created the tpl file for this new page: top10.tpl which contains:

{l s='Top 10'}

Top 10 content...
{$HOOK_CENTER}



My new page works, but only displays the title and "Top 10 content...". The hook doesnt show up and i really dont see why.

Any idea ?

Thanks in advance.

Share this post


Link to post
Share on other sites

Just found the solution on another post, i added this line to the files blocknewproducts.php and blockbestsellers.php both in the "modules" folder at the root of the site:

function hookCenter($params)
   {
       return $this->hookLeftColumn($params);
   }



The only thing bothering me is that i dont really understand what it does.

Share this post


Link to post
Share on other sites
Just found the solution on another post, i added this line to the files blocknewproducts.php and blockbestsellers.php both in the "modules" folder at the root of the site:

function hookCenter($params)
   {
       return $this->hookLeftColumn($params);
   }



The only thing bothering me is that i dont really understand what it does.



That function connects your hook and module.
It is necessary for displaying module in place where you put {$HOOK_CENTER}.
And code inside means that module will be displayed same as in left column.

Here is link that maybe explains it better.
http://www.ecartservice.net/03082009/writing-your-own-prestashop-module-part-5/

Share this post


Link to post
Share on other sites

Please Help Me.
I have been trying to do it for few hours now, with no luck. I changed the look of the FooterVariousLinks block and I want the NewsLetter Block to show there.

1. I added in the database a new hook called footernewsletter.
2. Then, in footer.php I added:

'HOOK_FOOTERNEWSLETTER' => Module::hookExec('footernewsletter'),


3. In blockvariouslinks.tpl I have added:

               {$HOOK_FOOTERNEWSLETTER}


4. In the blocvariouslinks.php I have added:

    public function footernewsletter(/*$params*/)
   {
       return $this->hookLeftColumn($params);
   }


5. In the blocknewsletter.php I have added:

public function footernewsletter(/*$params*/)
   {
       return $this->hookLeftColumn($params);
   }



I am not sure if i added the right tpl\php files. But the newsletter block would not show inside the variouslinks block. The various links block does show. I know that the footernewsletter hook is working because I can see it in the BO when I want to transplant the module...

Please guide me to my mistake. What am I dong wrong? What am I doing right? How to make the newsletter block show in the footer various links block? ( I created a table in the various links and I want the newsletter to show in a specific cell)

Thanks in advance.

Share this post


Link to post
Share on other sites

Hello kids, I need your help. I've been trying to create a custom hook according to the described method, but it gives me no results. After the endless hours of struggling with prestashop, I've found this dumb solution: apart from creating a custom hook in the ps_hook table, I must also modify the ps_hook_module table in order to associate the new hook with a module. Only this way I get results. And I wonder if there is a more elegant solution to this problem...

Share this post


Link to post
Share on other sites

Just to say that if you need to add a module to your new hook, you need to set something like this in the proper module's php file, like k-win pointed:

function hookCustomColumn($params)
   {
       return $this->hookLeftColumn($params);
   }



After that, you can position modules in your brand new hook.

Thanks for the tutorial ;o)

Share this post


Link to post
Share on other sites

Hi
I tried the steps from the first post to create the hook into a new page I created. But it won't show up. I'm basically trying to hook the Jgalleryview 2 module to a separate page called press with the overall theme & look of the site intact. I've attached my press.php and the jgalleryview2.php files, please let me know what I'm doing wrong.

My press.tpl is

 
In the Press 

{$HOOK_PRESS}



Thanks

press.php

jgalleryview2.php

Share this post


Link to post
Share on other sites

sperio you sound like a real hook specialist.

 

I have a question for you.

 

I accidentaly unhooked the Module ''Header Logos'' within ''Header of Pages''. Now I don't have any logo on my site.

The problem is that I cannot position ''Header Logos'' back to "Header of Pages".

 

I get the message:

 

This module cannot be aasigned to this hook. (not exactly the error message, because I translated the Dutch one)

 

Thanks for you help.

Share this post


Link to post
Share on other sites

hi, I am having hook problem. Here, I wan to make hook without going phpmyadmin and core files of prestashop. I have read several post and blog about creating hook but all of theme are updating data from phpmyadmin and updating files of prestashop core. But I did not find any nice post and tutor to create hook without touching core files of prestashop and phpmyadmin. Editing in core prestashop like FrontController.php or updateing FrontController.php in override/classes or updating template php file is not nice technique because if you update our prestashop then your hook will disapper. Not even that, even you can not install propery your theme easily if you had created extra hook.

 

Here, I have tried to get solution without out core file modification. Currently, I want to hook "parmanentlink block" into "devil" hook.

 

blockparmanentlinks.php

 

function install()
   {
           DB::getInstance()->execute("INSERT INTO "._DB_PREFIX_."hook
					    SET name= 'devil',
						    title= 'Devil',
						    description= 'Top Center contains userinfo'");
           return (parent::install() AND $this->registerHook('devil') AND $this->registerHook('header'));
   }
public function hookDevil($params)
   {
       global $smarty;
       /* Assign smarty for HOOK_DEVIL */
       $smarty->assign(array('HOOK_DEVIL' => Module::hookExec('devil')));
       print_r($smarty);
       return $this->display(__FILE__, 'blockpermanentlinks.tpl');
   }

 

 

header.tpl

{$HOOK_DEVIL}

 

While I install my module "block permanentlinks". It sucessfully install but with errors output

 

Notice: Undefined variable: HOOK_DEVIL in D:\www\e-commerce\test\prestashop\tools\smarty\sysplugins\smarty_internal_data.php on line 29

 

Download files:

That would be long breath taking for me and all prestashop designer if any one can solve this issue.

Share this post


Link to post
Share on other sites

Hello,

 

I have also created custom hook as you wrote in post,but it is showing nothing on front end.

In fashion.php file i have these functions:

 

function hookFashion($params)

{

global $smarty;

$smarty->assign(array(

'HOOK_FASHION' => Module::hookExec('fashion'),

'content_only' => intval(Tools::getValue('content_only'))));

return $this->display(__FILE__, 'fashion.tpl');

}

 

function install()

{

if (!parent::install())

return false;

$this->registerHook('fashion');

return true;

}

 

and in my store.tpl file i use

 

{$HOOK_FASHION}

Share this post


Link to post
Share on other sites

Hello,

 

I have also created custom hook as you wrote in post,but it is showing nothing on front end.

In fashion.php file i have these functions:

 

function hookFashion($params)

{

global $smarty;

$smarty->assign(array(

'HOOK_FASHION' => Module::hookExec('fashion'),

'content_only' => intval(Tools::getValue('content_only'))));

return $this->display(__FILE__, 'fashion.tpl');

}

 

function install()

{

if (!parent::install())

return false;

$this->registerHook('fashion');

return true;

}

 

and in my store.tpl file i use

 

{$HOOK_FASHION}

Share this post


Link to post
Share on other sites

You've got two little mistakes :

 

you forgot one dollar here : (line 27)

 

if (!$this->registerHook('rightColumn') OR !$this->registerHook('leftColumn') OR !$this->registerHook('home'))

 

and a bracet at the end

 

function hookHome($params)
	{
	return $this->hookRightColumn($params);
   }

}					<< here
?>

 

Don't forget to comment the hook you don't want in the install function. (with the file you give me, you've got the blocspecials in the left column, AND in the right column, AND in the home.)

 

Don't forget also that you will not display the specials the same way in a column or in the home !! I suggest you to replace the function hookHome with a duplicate of the hookRightColumn function, and rename the .tpl returned (and create it.)

 

Gook Luck !!

 

You are genius! It worked perfectly for me

Share this post


Link to post
Share on other sites

Took me quite a while and lots of meddling to figure this out... thought I would share with the rest of you guys on how to create a hook so u can NOT waste the number of hours like I did :)

 

 

1. Goto your database and modify ps_hook... (ps_ is what I named my database, so it can be replaced by what you named yours.)

 

 

2. find the last id_hook number and insert a new number after with the hook that you want to name e.g. I name it 'cat'

 

 

3. goto the php of the pages you want the hook to be in... e.g footer.php

 

 

4. insert 'HOOK_CAT' => Module::hookExec('cat'), into the below

 

$smarty->assign(array(
	'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn'),
	'HOOK_FOOTER' => Module::hookExec('footer'),
	'content_only' => intval(Tools::getValue('content_only'))));
	$smarty->display(_PS_THEME_DIR_.'footer.tpl');

 

 

 

5. this is the final code...

 

$smarty->assign(array(
	'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn'),
	'HOOK_FOOTER' => Module::hookExec('footer'),
	'HOOK_CAT' => Module::hookExec('cat'),
	'content_only' => intval(Tools::getValue('content_only'))));
	$smarty->display(_PS_THEME_DIR_.'footer.tpl');

 

 

6.insert {$HOOK_CAT} into where you want in footer.tpl and you are in business

 

 

NOTE : For the hook to appear YOU HAVE TO assign the array in the page's php... Would be good if we can have a master HOOK array list...

 

 

are this instructions available for PS V 1.5 or upper ???

some parts of your codes Does not exist at least in PS 1.5 files .. for example i didnt find this lines on both footer.php and footer.tpl :

 

		[code]$smarty->assign(array(
	'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn'),
	'HOOK_FOOTER' => Module::hookExec('footer'),
	'content_only' => intval(Tools::getValue('content_only'))));
	$smarty->display(_PS_THEME_DIR_.'footer.tpl');

[/code]

 

and better i say i didnt find in whole files and docs!!

 

anybody has a soloution ? or suggest ?

Edited by the_raven (see edit history)

Share this post


Link to post
Share on other sites

are this instructions available for PS V 1.5 or upper ???

some parts of your codes Does not exist at least in PS 1.5 files .. for example i didnt find this lines on both footer.php and footer.tpl :

 

	[code]$smarty->assign(array(
	'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn'),
	'HOOK_FOOTER' => Module::hookExec('footer'),
	'content_only' => intval(Tools::getValue('content_only'))));
	$smarty->display(_PS_THEME_DIR_.'footer.tpl');

[/code]

 

and better i say i didnt find in whole files and docs!!

 

anybody has a soloution ? or suggest ?

 

I would love an answer as well

Share this post


Link to post
Share on other sites

Hi,

I am trying to display categories horizontally. I have used "hcatmenu" module but at the time of transplantation error display "This module cannot be transplanted to this hook", any help regarding this is appreciable . 

Share this post


Link to post
Share on other sites

Hello,

 

There is no need to us any other module.I have use top- horizontal-menu module of leo-theme for displaying for cms page and top- horizontal-menu module for categories,categories will be automatically displayed horizontally.       

Share this post


Link to post
Share on other sites

Hi,

can we add layered navigation module to home page of prestashop.

currently iam using prestashop version 1.6.

if there a possibility cam you pls explain it to me as iam new to prestashop.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More