PrestaShop Forums: [ SOLUTION] Create Hooks in 6 easy steps! - PrestaShop Forums

Jump to content


Welcome to the PrestaShop Forum! We hope you'll share your comments and suggestions with us. We ask that you please post in English to the main sections of the PrestaShop Forum. If you want to write in another language, please post in the corresponding PrestaShop Community section below.

Please note that PrestaShop Community sections are largely self-moderated. PrestaShop team members may or may not participate in non-English sections. To improve the chances of receiving feedback to your question or comment, please post it in English to the main sections of our Forum.

NYC

Vous parlez français ? par ici !


[ SOLUTION] Create Hooks in 6 easy steps!


[ SOLUTION] Create Hooks in 6 easy steps!

#1 sperio

    PrestaShop Apprentice

  • 15 Jan 2009
  • Members
  • PipPip
  • 75 posts

Posted 12 February 2009 - 03:41 AM

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...
----------------------------------------
http://www.zuigeling.com
http://www.iputa.com
http://www.alfredtay.com
----------------------------------------

#2 wdld

    PrestaShop Newbie

  • 28 Jan 2009
  • Members
  • Pip
  • 4 posts

Posted 17 February 2009 - 02:03 PM

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:
[size=3]www.webdesigner-logodesign.com[/size]

#3 SotEW

    PrestaShop Addict

  • 17 Jul 2008
  • Members
  • PipPipPip
  • 990 posts

Posted 17 February 2009 - 02:36 PM

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.
Posted Image
Add content on your PrestaShop website (pictures, flash, html and SLIDESHOW) with AddBlocks V1.4 Posted Image
Documentation for AddBlocksV1.3b (french and english)
Demo website: http://demo.sotew.com/ - http://demo.sotew.com/back/

#4 wdld

    PrestaShop Newbie

  • 28 Jan 2009
  • Members
  • Pip
  • 4 posts

Posted 18 February 2009 - 05:19 AM

thanks SotEW
This code is working :-)

Attached File(s)


[size=3]www.webdesigner-logodesign.com[/size]

#5 sperio

    PrestaShop Apprentice

  • 15 Jan 2009
  • Members
  • PipPip
  • 75 posts

Posted 18 February 2009 - 05:26 AM

glad you guys like it
----------------------------------------
http://www.zuigeling.com
http://www.iputa.com
http://www.alfredtay.com
----------------------------------------

#6 Ardian Yuli Setyanto

    PrestaShop Fanatic

  • 06 Jan 2009
  • Moderators
  • 1022 posts
  • Location:Yogyakarta, Solo, Wonogiri, Karanganyar Indonesia

Posted 18 February 2009 - 07:08 AM

thanks for tutorial

#7 DannyIDC

    PrestaShop Newbie

  • 12 Mar 2009
  • Members
  • Pip
  • 11 posts

Posted 21 March 2009 - 02:25 PM

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.

#8 SotEW

    PrestaShop Addict

  • 17 Jul 2008
  • Members
  • PipPipPip
  • 990 posts

Posted 21 March 2009 - 02:50 PM

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 ;)
Posted Image
Add content on your PrestaShop website (pictures, flash, html and SLIDESHOW) with AddBlocks V1.4 Posted Image
Documentation for AddBlocksV1.3b (french and english)
Demo website: http://demo.sotew.com/ - http://demo.sotew.com/back/

#9 DannyIDC

    PrestaShop Newbie

  • 12 Mar 2009
  • Members
  • Pip
  • 11 posts

Posted 21 March 2009 - 03:03 PM

See the file please and tell me where's the problem, please :)

Attached File(s)



#10 SotEW

    PrestaShop Addict

  • 17 Jul 2008
  • Members
  • PipPipPip
  • 990 posts

Posted 21 March 2009 - 05:24 PM

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 !!
Posted Image
Add content on your PrestaShop website (pictures, flash, html and SLIDESHOW) with AddBlocks V1.4 Posted Image
Documentation for AddBlocksV1.3b (french and english)
Demo website: http://demo.sotew.com/ - http://demo.sotew.com/back/

#11 DannyIDC

    PrestaShop Newbie

  • 12 Mar 2009
  • Members
  • Pip
  • 11 posts

Posted 21 March 2009 - 06:14 PM

Works good! Thanks a lot. ;)

#12 Presta-TR

    PrestaShop Addict

  • 12 Nov 2008
  • Members
  • PipPipPip
  • 544 posts

Posted 27 March 2009 - 06:58 PM

i am adds a block to header bottom. but this area is 2 row. i need one row.

#13 cerberus22

    PrestaShop Apprentice

  • 02 Jan 2009
  • Members
  • PipPip
  • 275 posts

Posted 23 April 2009 - 02:49 PM

works well, thanks for the info.

all the best,
cerberus22
Using Prestashop V1.1

#14 buggy

    PrestaShop Newbie

  • 06 May 2009
  • Members
  • Pip
  • 3 posts

Posted 06 May 2009 - 10:22 AM

Thanks for the tutorial.. saved me hours

#15 sperio

    PrestaShop Apprentice

  • 15 Jan 2009
  • Members
  • PipPip
  • 75 posts

Posted 04 June 2009 - 12:34 PM

we can help if you would provide us with the problem :)
----------------------------------------
http://www.zuigeling.com
http://www.iputa.com
http://www.alfredtay.com
----------------------------------------

#16 swift

    PrestaShop Newbie

  • 14 Jan 2009
  • Members
  • Pip
  • 2 posts

Posted 30 June 2009 - 04:19 PM

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?


#17 google-friend

    PrestaShop Apprentice

  • 03 Jul 2009
  • Members
  • PipPip
  • 66 posts

Posted 07 July 2009 - 12:47 AM

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.

#18 visua

    PrestaShop Newbie

  • 11 Nov 2008
  • Members
  • Pip
  • 24 posts

Posted 15 August 2009 - 08:26 PM

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.

#19 coalesce

    PrestaShop Apprentice

  • 22 Jul 2009
  • Members
  • PipPip
  • 74 posts

Posted 29 December 2009 - 10:07 PM

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!
www.coalesce.us

#20 guyen

    PrestaShop Newbie

  • 27 Jan 2010
  • Members
  • Pip
  • 12 posts

Posted 21 February 2010 - 03:26 PM

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users