Jump to content

Recommended Posts

Hi friend's

 

__________________________________________________________________

I strongly recommend you first to use the new method

( $this->registerHook('displayMyNewHook'); )

for ps 1.5 ,because its easier and cleaner and doesn't need to add field to database manually but if you can't use that way you can use instruction Below..you can find complete detail about new method on this >> Topic >> writed by Fabien Serny

___________________________________________________________________________________

 

 

This tutorial edited for use on Prestashop ver 1.5.4 ( latest version )

I want to show you how create a custom hook in PS 1.5.4 in 4 simple steps .

 

Step 1 : Open PphMyAdmin .find your shop database and open it.

 

in prestashop you need to create one Row in "ps_hook" table.

 

 

first open ps_hook table and Insert new Row and name it for example displayTop2 .

 

 

you just need to fill name and title field's.not any other values needed.

 

 

 

Step 2 : in this step you need to register your new Hook in prestashop.

 

open your shop root folder .open classes >> controller >> FrontController.php file. find displayHeader or displayTop using your editor search tool.you must find this lines :

 

'HOOK_TOP2' => Hook::exec('displayTop2'),

 

 

add this line after 'HOOK_TOP' => Hook::exec('displayTop') and next you must have this :

$this->context->smarty->assign(array(
'HOOK_HEADER' => Hook::exec('displayHeader'),
'HOOK_TOP' => Hook::exec('displayTop'),
'HOOK_[color=#008000][b]displayTop2[/b][/color]' => Hook::exec('[b]displayTop2[/b]'),
'HOOK_LEFT_COLUMN' => ($this->display_column_left ? Hook::exec('displayLeftColumn') : ''),
'HOOK_RIGHT_COLUMN' => ($this->display_column_right ? Hook::exec('displayRightColumn', array('cart' => $this->context->

 

 

search again with DisplayTop value and you may see the same above lines again :

 

$this->context->smarty->assign(array(

'HOOK_HEADER' => $hook_header,

'HOOK_TOP' => Hook::exec('displayTop'),

 

'HOOK_displayTop2' => Hook::exec('displayTop2'),

 

'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)) : ''),

'HOOK_FOOTER' => Hook::exec('displayFooter')

));

 

 

and add 'HOOK_displayTop2' => Hook::exec('displayTop2'), after 'HOOK_TOP' => Hook::exec('displayTop'), again.

 

Step3 : add this line where you want to your hook be there :

 

<div id='myCustomHook'> {$HOOK_displayTop2} </div>

 

for example you can add this line to Header.tpl on top of the page.

 

 

 

Step4 : you can now easily tranplant your modules to this hook by PS admin tools, but may be some modules return this error : this modules can't transplant to this hook!

 

for solve this issue you must do this instruction :

1 - goto you php file of your module

2 - add this lines before this type of functions ( Home , Header or .. ) :

function hookdisplayTop2($params) {
	return $this->hookhome($params, 'displayTop2');
}

 

you must change the step 4 based on your module and i wrote this function just for an example..

 

 

good luck..

Edited by the_raven (see edit history)
  • Like 10
Link to comment
Share on other sites

  • 3 weeks later...

Hi,

Very good tutorial!!! (best I've ever seen) but I got some problems (PrestaShop 1.5.3.1) I done all that steps and when I try add new product block to the new hook we created all website crash "Error HTTP 500 (Internal Server Error)"

 

Any idea how to fix it?

 

P.S.

The issue comes just after I add these:

function hookTop2($params) {

return $this->hookhome($params, 'top2');

}

 

to the blocknewproducts.php

Edited by sieja (see edit history)
Link to comment
Share on other sites

hi buddy

 

please give me some detail about your new hook and tell me where is your new hook.

 

blocknewproducts is a type of modules that designed for right or left column hook's .

 

you must do the instruction to step 4 exactly same as same that i wrote on my post .. but you must change the Step 4 for based on your modules need.

for example in blocknewproducts.php you have this codes at the end of blocknewproducts.php :

 

public function hookRightColumn($params)
{
 $newProducts = Product::getNewProducts((int)($params['cookie']->id_lang), 0, (int)(Configuration::get('NEW_PRODUCTS_NBR')));
 if (!$newProducts && !Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY'))
  return;
 $this->smarty->assign(array(
  'new_products' => $newProducts,
  'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
 ));
 return $this->display(__FILE__, 'blocknewproducts.tpl');
}
public function hookLeftColumn($params)
{
 return $this->hookRightColumn($params);
}
public function hookHeader($params)
{
 $this->context->controller->addCSS(($this->_path).'blocknewproducts.css', 'all');
}
}

 

as you see this module designd forright and left column and has two function for this hooks ( hookRightColumn , hookLeftColumn ) .

 

now tell me where is your new hook ? has it the same situation as hookRightColumn and hookLeftColumn ?

Edited by the_raven (see edit history)
  • Like 1
Link to comment
Share on other sites

Hey there

 

basically I try to add new product to the center column of home page(instead of slider), I've seen nice slider but couldn't find these module

based on source page

<div id="featured_products_slider" class="flexslider_carousel">

that can be flexslider

Link to comment
Share on other sites

ok ,in this case its not necessary to create new hook ! you want to tranplant new product to home ,and you have the Home Hook right now! you just need to add a function to blocknewproducts.php. so add new function after public function hookLeftColumn with this content :

 

 

function hookhome($params) {

return $this->hookRightColumn($params);

}

 

now you need do some css to match the module in Home hook.

  • Like 1
Link to comment
Share on other sites

Thank You for your help

 

I got one more question. Homefeatured module is based in presta directory with CSS file is any chance apply these CSS to new theme? for example on the end I want to export this theme and update on my serwer what happen with hemefeatured CSS file? (if is only in root module folder)

 

P.S.

When I add new style to global.css(my theme) instead hemefeatured.css(root) nothing happen

Edited by sieja (see edit history)
Link to comment
Share on other sites

your welcome

 

i havent worked with template export yet , and if want to transport my shop to server , i will copy all of my shop files to server and backup database file and restore backup to server.

when you need to apply your small changes to your server, you just need to replace the target files...for example when you change the global.css you just need to update global css on server.

 

some thems has some changes for homefeatured module (and other modules ) and if you see you have a module folder in your theme folder..some module use some files on shop root folder and use some files from theme folder.

 

if your changes on homefeatured are honored and your customizations applied, now when you export your theme to your server you must copy homefeatured files from local root to server root ( on module folder ) ( you may have duplicate folder frome on module, one in root folder and one in theme folder, you must save both folder and your shop needs both)

Edited by the_raven (see edit history)
  • Like 1
Link to comment
Share on other sites

some modules has a special css files in modules root folder( usually in CSS folder ), and some modules use golbal css . you can tell you module to use global css and copy all the codes in module css folder to golbal files, but you need to do a small change on your module, and remove css load line from module tpl files ( or php) .

 

in short, when you want your module use golbal.css , your module Should'nt load any css files directly.

Link to comment
Share on other sites

  • 3 weeks later...

Hello Raven,

 

This is not true. You can easily work with the multiple CSS from your module through the addCSS() method as long you define an ID which is unique and which will override any global CSS settings.

 

That said you can always define all your HTML between a <div id="mycustomCSSDefinitions"></div> within your template file (.tpl) and start any definitions of your CSS with: #mycustomCSSDefinition fieldset { , etc.... and it will just work fine.

 

In that scenario you just override what you need and you will still be able rely fully on the global CSS which is I think a major advantage.

 

Finally, there is absolutely no need to define a hook alias when creating a new hook unless you want more friendly names to be defined.

 

This was my two cents ;-)

 

BR,

RaPhiuS

Link to comment
Share on other sites

  • 1 month later...

Hi Raven,

 

This is a really good guide for a newbie to understasnd and create hi/her own custom hook.

 

It would be better if you could associate this tutorial with CMS page. I mean How to create Hook and hook a module in a CMS page. in his way this tutorial will be more useful for those who want to create a hook and hook their modules to their CMS pages.....

 

The reason why i suggest this to you because this guide written in such a way that every one can understand....

 

Thanks!

Link to comment
Share on other sites

  • 2 weeks later...

Hello Raven,

 

This is not true. You can easily work with the multiple CSS from your module through the addCSS() method as long you define an ID which is unique and which will override any global CSS settings.

 

That said you can always define all your HTML between a <div id="mycustomCSSDefinitions"></div> within your template file (.tpl) and start any definitions of your CSS with: #mycustomCSSDefinition fieldset { , etc.... and it will just work fine.

 

In that scenario you just override what you need and you will still be able rely fully on the global CSS which is I think a major advantage.

 

Finally, there is absolutely no need to define a hook alias when creating a new hook unless you want more friendly names to be defined.

 

This was my two cents ;-)

 

BR,

RaPhiuS

 

hi

sorry for delay

it seems you are right and your method is true but its better to give us an example so we can underestand your saying better.

 

thank you

Link to comment
Share on other sites

Hi Raven,

 

This is a really good guide for a newbie to understasnd and create hi/her own custom hook.

 

It would be better if you could associate this tutorial with CMS page. I mean How to create Hook and hook a module in a CMS page. in his way this tutorial will be more useful for those who want to create a hook and hook their modules to their CMS pages.....

 

The reason why i suggest this to you because this guide written in such a way that every one can understand....

 

Thanks!

 

sorry for delay

thanks for your attention and your suggestion.

 

i will try to find a simple way to create custom hook on cms page soon. ;)

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Hi raven, i have to create action hook, which will be placed on product detail page. By following the steps i have created the module and hook. But when i position my module to that hook, all the site crashes. can you guide me how i can solve this issue???

Link to comment
Share on other sites

Hi raven, i have to create action hook, which will be placed on product detail page. By following the steps i have created the module and hook. But when i position my module to that hook, all the site crashes. can you guide me how i can solve this issue???

 

there are other and better ways for create custom hook in prestashop that you can find them and use them, if the way in this topic is not Efficient for you.

 

but i think you had a mistake in one of above steps.because if you do a simple syntax mistake in php your whole website goes down.

 

check all steps again.and try too check the module in other hook's. don't forget to check module.php file to get certainty that your module has abality for tranplaning on New hook that you made it..

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...
  • 2 weeks later...
  • 2 weeks later...

No, no and no :)

 

This is the way you have to do it...:

 

First Step

In your install method into the module: $this->registerHook('nameOfHook');

 

Final Step

In your TPL files: add this one {hook h='nameOfHook'} (or {hook h='nameOfHook' mod='moduleName'}

 

And it's all. Easier, isn't ? And better, too ! ;-)

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

No, no and no :)

 

This is the way you have to do it...:

 

First Step

In your install method into the module: $this->registerHook('nameOfHook');

 

Final Step

In your TPL files: add this one {hook h='nameOfHook'} (or {hook h='nameOfHook' mod='moduleName'}

 

And it's all. Easier, isn't ? And better, too ! ;-)

 

yeah you right but if you read the first paragraph of first post of this topic you see that i have mentioned to method that you said.. ;-)

thank you

Edited by the_raven (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Hi the_raven, thanks for your guide, it's very well explained.

 

Thanks for your help :)

 

your welcome

which method did you use ? new mothod or old ? did you create database table manually ?

 

if you use new method database table create automatically and its good when you use your template in new shop ! template create the table automatically.

Link to comment
Share on other sites

Hmm I created the entry in the table manually, but that wasn't the "hard point".

I wanted to create a new hook for the Homeslider module to be displayed on my CMS pages.

Here are some explanations for newb like me for things i spent time on:

 

For Step2 :

 

We want to create a smarty variable for our hook so we can use it later.

In my case :

$this->context->smarty->assign(array(
	'HOOK_HEADER' => Hook::exec('displayHeader'),
	'HOOK_CMS' => Hook::exec('displayCmsBody'),
	'HOOK_TOP' => Hook::exec('displayTop'),

 

Step 3 :

 

We now want to display this hook.

So we just add this line in the right tpl file. In my case cms.tpl

<div id='myCustomHook'> {$HOOK_CMS} </div>

Notice that $HOOK_CMS is the smarty variable we assigned before.

 

Step 4 :

 

Now we have add the display function associated to our hook.

You have to name it hookYourHookName.

 

public function hookDisplayCmsBody($params)
{
  // DISPLAY CODE
}

 

To find the display code you just have to look at the existing functions for exemple :

 

public function hookDisplayCmsBody($params)
{
 if(!$this->_prepareHook())
  return;
 // Check if not a mobile theme
 if ($this->context->getMobileDevice() != false)
  return false;
 $this->context->controller->addJS($this->_path.'js/jquery.bxSlider.min.js');
 $this->context->controller->addCSS($this->_path.'bx_styles.css');
 $this->context->controller->addJS($this->_path.'js/homeslider.js');
 return $this->display(__FILE__, 'homeslider.tpl', $this->getCacheId());
}

 

Tell me if i said stupidities. That can be obvious for you but i think it can help some :)

Link to comment
Share on other sites

Hmm I created the entry in the table manually, but that wasn't the "hard point".

I wanted to create a new hook for the Homeslider module to be displayed on my CMS pages.

Here are some explanations for newb like me for things i spent time on:

 

For Step2 :

 

We want to create a smarty variable for our hook so we can use it later.

In my case :

$this->context->smarty->assign(array(
	'HOOK_HEADER' => Hook::exec('displayHeader'),
	'HOOK_CMS' => Hook::exec('displayCmsBody'),
	'HOOK_TOP' => Hook::exec('displayTop'),

 

Step 3 :

 

We now want to display this hook.

So we just add this line in the right tpl file. In my case cms.tpl

<div id='myCustomHook'> {$HOOK_CMS} </div>

Notice that $HOOK_CMS is the smarty variable we assigned before.

 

Step 4 :

 

Now we have add the display function associated to our hook.

You have to name it hookYourHookName.

 

public function hookDisplayCmsBody($params)
{
  // DISPLAY CODE
}

 

To find the display code you just have to look at the existing functions for exemple :

 

public function hookDisplayCmsBody($params)
{
 if(!$this->_prepareHook())
  return;
 // Check if not a mobile theme
 if ($this->context->getMobileDevice() != false)
  return false;
 $this->context->controller->addJS($this->_path.'js/jquery.bxSlider.min.js');
 $this->context->controller->addCSS($this->_path.'bx_styles.css');
 $this->context->controller->addJS($this->_path.'js/homeslider.js');
 return $this->display(__FILE__, 'homeslider.tpl', $this->getCacheId());
}

 

Tell me if i said stupidities. That can be obvious for you but i think it can help some :)

 

hi wapazz

i have read your last post.

the important matter is that for prestashop version 1.5 + its better for you to use new method. i have writen this tutorial before i use new method in ps 1.5 . but at first of the tutorial i recommend you to use new method . ok i explain new method here again and then we talk about displaying homeslider in your cms page .

 

in new method you don't need to create new field in database and you don't need to create smarty variables too ! no class edit needed . just do this instruction :

 

in your tpl file for example header.tpl create a new DIV and put it on header section :

 

<div id="myNewHook" {hook h='displayMyNewHook'} </div>

 

Then

 

open module.php for example homeslider.php

 

your must edit two part of the whole codes.first edit this part :

 

public function install()
{
 /* Adds Module */
 if (parent::install() && $this->registerHook('displayHome') && $this->registerHook('actionShopDataDuplication'))
 {

change it too :

 

public function install()
{
 /* Adds Module */
 if (parent::install() && $this->registerHook('displayMyNewHook') && $this->registerHook('actionShopDataDuplication'))
 {

 

and next edit this part :

 

public function hookDisplayHome()
{
 if(!$this->_prepareHook())
  return;
.
.
.

 

to

 

public function hookDisplayMyNewHook()
{
 if(!$this->_prepareHook())
  return;
.
.
.

 

and it will create your new hook and display your module on it.

uninstall and reinstall the module and it wiil displayed on new hook that you have made it.

 

 

now you can use simple if to display your new hook on every page you want.for example :

 

before the DIV you have made it on Header.tpl put a simple if :

 

{if $page_name !== 'index'}

<div id="myNewHook" {hook h='displayMyNewHook'} </div>

{/if}

 

and it will show homeslider only in home page and you can do the same for cms page .

 

 

maybe there are better ways for displaying homeslider on cms page but this is the way i thinks simpler ;-)

Edited by the_raven (see edit history)
  • Like 1
Link to comment
Share on other sites

I deleted my prestashop to work on clean bases (i modified many php files). Everything worked on the first try.

Indeed the new version is even simplier. Thanks :)

 

It works, my slider is displayed on the cms page, but its not a slider anymore, every slide are displayed one below the other (as old browsers).

 

Other thing, i want two sliders :

(That's not an hook problem anymore should we continue in another thread ?)

One for my homepage and one for my cms page. If i allow my module to be displayed on both pages the configuration is the same and i cant change my slides.

I'm looking for how to duplicate this module, i red some guides, but exemples are on the homefeatured module which is very simple, the homeslider as many database actions. When i duplicate it the site crashes.

Link to comment
Share on other sites

the problem with your homeslider is that the css and maybe js files doesn't load. you must attach the css files to header .put this code :

 

public function hookHeader()

{

 

$this->context->controller->addJS($this->_path.'js/jquery.bxSlider.min.js');

$this->context->controller->addCSS($this->_path.'bx_styles.css');

$this->context->controller->addJS($this->_path.'js/homeslider.js');

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

}

 

above the :

public function hookDisplayMyNewHook()

{

if(!$this->_prepareHook())

return;

.

.

.

and i think your problem will solve.

remember with this new mothod you allways need to attach the css and js filed to header.

 

and about the other

 

duplicating a module sometimes is simple and sometimes goes a little complicated.

 

if you want to do it then leave your first home slider to default hook and we dont need it anymore.

 

you just need to create new hook for your new homeslider that you should use " if " to display it only on cms page.

 

Next

 

if you Insist on having a home slider as the same as prestashop default homeslider i will help you to duplicate the module.

 

But

 

if no i offer you to use another Slideshow that its even better the ps default slider. you can download it and install it as a module and open the module TPL file and put the whole code in IF block . so prestashop display the module only if the page index is cms.

with this way you may don't need to create new hook anymore :-) and maybe you need ( Liaise on you need's).

you can download the slider here : NivoSlider you can see the demo here : Demo :rolleyes:

 

tell me if its not usefull for you ;)

Link to comment
Share on other sites

Hey thanks again for your advice, once again it was just right :)

I didn't add the js with the new method.

 

The module you linked is really cool.

In fact i was planning to have something like 12 sliders. So i had to duplicate the module, but finally i think this will annoy the customer, so i decided to keep only one slider in the homepage, i changed to your module which is way better than the default one.

 

Sorry to wasted your time on these questions but i learned a lot :)

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

your welcome , Our goal is learning.we must learn from each other ;) good luck

 

Hi the_raven,

 

I'm newbie too in this arena :)

 

I'm trying to add a new hook for product page, actually I wanted to copy the product price and Add to cart button + useful links (facebook, add to fav and print buttons) at the end of product page too after attributes.

 

There are pb-right-column and pb-left-column for price and useful links.

 

I don't want to hack the core but wanted to create our own hook so in future if we wanted to remove that think, we can simply unhook from BO.

 

What I figured out is to create a manual entry in ps_hooks table (I'm using PS 1.5.4)

 

Wanted to override the frontController file by definging another class in override/front/frontOverrideClass there I'll be defining a new line of code with my newPositionHook under initContent() function

 

then I'll be using that smarty assigned variable for newPositionHook in proudct.tpl page and using it at the bottom of products attribute content where I wanted to show that new things.

 

Please guide me am I doing that right so is there any clean solution for that?

 

Thanks,

Nadeem

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

OK, I'm not sure if any of you guys put this in the post because when I got to second post page the code You put scared me.

What I was looking for:

a way to use made modules in templates wherever I want.

Without modifying the original module you can put anywhere in .tpl in your cusom theme (module update won't overwrite your changes):



{hook h='oneOfModulesHooks' mod='modulename'}

And then you can do a .tpl override in youre theme/modules/modulename/template.tpl (you have to copy the template you want to change from module folder)

 

I know that this topic was about something bit different, but I was looking for my method for few hours, so I hope it'll help someone :]

Edited by hypermotion (see edit history)
Link to comment
Share on other sites

  • 1 month later...

i have put this code

 

function hookdisplayTop2($params) {
        return $this->hookhome($params, 'displayTop2');
    }

 

on blocknewproducts.php but my newproduct module doesnt appear on cms.tpl 

also i put {$HOOK_displayTop2} this on cms.tpl file i want this module on my cms.tpl how to addd?? please give me some solution for this .  :huh::( :( :( :( :(

 

Edited by gauri (see edit history)
Link to comment
Share on other sites

ok ,in this case its not necessary to create new hook ! you want to tranplant new product to home ,and you have the Home Hook right now! you just need to add a function to blocknewproducts.php. so add new function after public function hookLeftColumn with this content :

 

 

function hookhome($params) {

return $this->hookRightColumn($params);

}

 

now you need do some css to match the module in Home hook.

I'm trying to hook the blocklayered module to price-drop page. I created a new hook displaypricedrop, I did define this in frontcontroller but I don't know what to put in blocklayered.css . Can you help me?

Link to comment
Share on other sites

can you show your code from frontcontroller?

btw. why you use frontcontroller instead of just pricesdrop controller?

I wasn't thinking to use that controller, because I was following the step by step tutorial of this topic:

Step 2 : in this step you need to register your new Hook in prestashop.

 

open your shop root folder .open classes >> controller >> FrontController.php file.

 

What should be the correct steps for me?

Link to comment
Share on other sites

  • 4 months later...

Hi, i need show homeslider in own hook. But doesnt work.

 

in homeslider.php

function hookdisplayTop2($params){
	return $this->hookhome($params, 'displayTop2');

 
	if ($this->context->getMobileDevice() != false)
	return false;
 
	$this->context->controller->addJS($this->_path.'js/jquery.bxSlider.min.js');
	$this->context->controller->addCSS($this->_path.'bx_styles.css');
	$this->context->controller->addJS($this->_path.'js/homeslider.js');
	return $this->display(__FILE__, 'homeslider.tpl');
}

edit:ok problem is here header.tpl

 

not correct 

<div id='myCustomHook'> {$HOOK_displayTop2} </div> 

correct 

<div id='myCustomHook'> {$HOOK_TOP2} </div>
Edited by tozi (see edit history)
Link to comment
Share on other sites

  • 4 weeks later...

Hi,, the_raven , i followed all this step . but still i have this error message "This module cannot be transplanted to this hook.".

 

i am trying hook this  in Tags block module.

i added this function  before    :-  function hookRightColumn($params) in blocktags.php

function hookdisplayTop2($params) {
        return $this->hookhome($params, 'displayTop2');
    }

plz.. any idea , what i missed!

Thanks

Link to comment
Share on other sites

Hi, i followed all steps described in http://www.prestashop.com/forums/topic/2182[spam-filter]create-custom-and-new-hook-in-ps-15/

 

But still i have this error message "This module cannot be transplanted to this hook.".

1st i added "displayTop2" hook in database . and final step(4th step) add this function code [

function hookdisplayTop2($params) {
        return $this->hookhome($params, 'displayTop2');
    }

]  in to blogtags.php

Actually,, i did all copy several times.. but still dont get solutions !

Link to comment
Share on other sites

hello

it's more than strange.

 

try to use function with "public"

public function hookdisplayTop2($params) {
    return $this->hookhome($params, 'displayTop2');
}

btw.

while you're trying to transplant module to this hook, are you 100% sure that you select "displayTop2" instead of "displayTop" ?

Link to comment
Share on other sites

  • 4 months later...

Hi,

 

I can't get to it... 

 

I want to Hook blockcart to the hook 'SHOPPINGBAG'.. In frontcontroller this is my code:

public function initContent()
	{
		$this->process();
		if (!isset($this->context->cart))
			$this->context->cart = new Cart();
		if (!$this->useMobileTheme())
		{
			// These hooks aren't used for the mobile theme.
			// Needed hooks are called in the tpl files.
			$this->context->smarty->assign(array(
				'HOOK_HEADER' => Hook::exec('displayHeader'),
				'HOOK_TOP' => Hook::exec('displayTop'),
				'HOOK_SHOPPINGBAG' => Hook::exec('displayShoppingBag'),
				'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)) : ''),
			));
		}
		else
			$this->context->smarty->assign('HOOK_MOBILE_HEADER', Hook::exec('displayMobileHeader'));
	}

I also have added the rule to the second bunch of lines in frontcontroller.php in the exact same way.

 

In blockcart.php I have tried so many things but in the end I came up with the code given in this tutorial: 

public function hookShoppingBag($params) {
	return $this->hookheader($params, 'displayShoppingBag');
}

Maybe I've done something wrong in the code above.

 

I want to place the hook in header.tpl this is the code I've used:

<div class="shoppingbag">
	{$HOOK_SHOPPINGBAG}
</div>

I also have tried {hook h="displayShoppingBag"}.

 

Since I'm new to prestashop I might have made a stupid mistake.. But I'm stuck on this thing for a couple of hours, I really appreciate any kind of help. Thanks!

Link to comment
Share on other sites

  • 11 months later...

Hello , Is this working for prestashop 1.6, because I have tried, and nothing shows up

 

  public function initContent()
    {
        $this->process();

        if (!isset($this->context->cart)) {
            $this->context->cart = new Cart();
        }

        if (!$this->useMobileTheme()) {
            // These hooks aren't used for the mobile theme.
            // Needed hooks are called in the tpl files.
            $this->context->smarty->assign(array(
                'HOOK_HEADER'       => Hook::exec('displayHeader'),
                'HOOK_TOP'          => Hook::exec('displayTop'),
                'HOOP_MENU'         => Hook::exec('displayMenu'),
                '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)) : ''),
            ));
        } else {
            $this->context->smarty->assign('HOOK_MOBILE_HEADER', Hook::exec('displayMobileHeader'));
        }
    }

this is my initContent() method, but is not working, can you give me a  hint?

Link to comment
Share on other sites

  • 7 months later...

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...