Jump to content
iliketodesign

[SOLVED] How to create a new hook in 1.5? Am I doing it wrong?

Recommended Posts

What I'm trying to achieve is the following: I create a new hook, add the "featured products on the homepage" module to it and then display it on a specific CMS page using. I've updated the php file in the "featured products on the homepage" to load in my new hook rather than on the homepage.

 

In Prestashop 1.4.x, when I wanted to register a new hook, I followed the steps in this tutorial: http://landofcoder.com/prestashop/guides/how-to-add-new-hook-in-prestashop-14.html

 

All is well and fine in 1.5. I create a new hook, transplant the module into the hook I've created and looks to be working.

 

But when I visit the page that should be displaying the module, I get the following error:

 

Notice: Undefined index: HOOK_ALLPRODUCTS in /var/www/vhosts/yourlogogoeshere.ca/tckl/cache/smarty/compile/dee8cb5cf1a740316c015d6fe3db7d60bf17be67.file.cms.tpl.php on line 67

 

Notice: Trying to get property of non-object in /var/www/vhosts/yourlogogoeshere.ca/tckl/cache/smarty/compile/dee8cb5cf1a740316c015d6fe3db7d60bf17be67.file.cms.tpl.php on line 67

 

What am I doing wrong? Or can someone point me in the right direction?

Share this post


Link to post
Share on other sites

Hi,

 

The tutorial seems good. What did you put in your FrontController override ?

 

Best regards,

Share this post


Link to post
Share on other sites

Fabien, thanks for replying.

 

I ended up figuring it out. Initially I took the FrontController file from the tutorial (which was causing the problems) but ended up replacing the code with the following:

 

class FrontController extends FrontControllerCore {
public function initContent()
{
 $this->process();
 if ($this->context->getMobileDevice() == false)
 {
  // 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_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_ALLPRODUCTS' => Module::hookExec('allproducts'),
  ));
 }
 else
 {
  $this->context->smarty->assign(array(
   'HOOK_MOBILE_HEADER' => Hook::exec('displayMobileHeader'),
  ));
 }
}
}

 

adding:

 

'HOOK_ALLPRODUCTS' => Module::hookExec('allproducts'),

Share this post


Link to post
Share on other sites

Hello,

I tried to create a new Hook in PS 1.5.0.13 following next steps to add something only after the manufacturer page.

1./ create in ps_hook

INSERT INTO `ps_hook` (
`id_hook` ,
`name` ,
`title` ,
`description` ,
`position`
)
VALUES (
NULL , 'afterManufacturer', 'after Manufacturer', NULL , '1'
);

2./ overide class FrontController

class FrontController extends FrontControllerCore {
public function initContent()
{
 $this->process();
  $this->context->smarty->assign(array(
'HOOK_HEADER' => Hook::exec('displayHeader'),
'HOOK_TOP' => Hook::exec('displayTop'),
'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_AFTERMANUFACTURER' => Module::hookExec('aftermanufacturer'),
  ));
 }
}

but I do not see the hook in the positions list in BO. What's wrong ?

Thanks...

Share this post


Link to post
Share on other sites

i have the same problem, nobody hasn't got any Solution ?

 

all the topics about create hooks dosn't usefull for prestashop 1.5.X !!!

Edited by the_raven (see edit history)

Share this post


Link to post
Share on other sites

As far as i remember the hook is supposed to be in the prestashop database too, ps_hook table.

Then it should appear in BO...

Share this post


Link to post
Share on other sites

You can create new hook in 1.5 on a easier way. I added this system since 1.5.0.7 (or one version before)

 

In your template :

{hook h='displayMyNewHook'}

 

And in your module in your module's install method :

$this->registerHook('displayMyNewHook');

 

Then add this method to your module :

public function hookDisplayMyNewHook($params) {

}

 

No need to assign hook in controller via override anymore in 1.5 :)

  • Like 3

Share this post


Link to post
Share on other sites

You can create new hook in 1.5 on a easier way. I added this system since 1.5.0.7 (or one version before)

 

In your template :

{hook h='displayMyNewHook'}

 

And in your module in your module's install method :

$this->registerHook('displayMyNewHook');

 

Then add this method to your module :

public function hookDisplayMyNewHook($params) {

}

 

No need to assign hook in controller via override anymore in 1.5 :)

 

yeah your method is too simple,but by this way your hook doesn't appear on Admin panel and position page..and somtimes we need to access the hook on admin panel..

Share this post


Link to post
Share on other sites

What do you mean by too simple ?

For making the hook appear in you admin panel, you just have to set the flag "position" to 1 in your database.

 

Make an override to assign a display hook in 1.5 is not a good think to do.

  • Like 1

Share this post


Link to post
Share on other sites

And no need to add hook in database table ps_hook anymore too

 

simple mean easy and fast and maybe better than the way i suggested but you said No need to add hook in DB and if we havent the hooks on DB we cant see them on admin panel ...

Share this post


Link to post
Share on other sites

I said "No need to add hook in DB" but it doesn't mean the hook is not added.

I changed the code of registerHook in module class.

 

Now when you do for example

$this->registerHook('displayMySuperNewHook'); it will check if the hook exists. If not, it will add it in ps_hook.

 

The fact that you do not see it in your back office, it's because you have to set the flag "position" to 1 in your table.

(I forgot to set this flag when I coded it).

 

So, as I said, overriding your controller is useless and not necessary :)

Share this post


Link to post
Share on other sites

sorry i did your instruction and back office return me some errors:

 

The following module(s) could not be loaded:

 

 

is it possible to discribe your method with a one of prestashop defualt modules ?

 

for example we add new DIV in header.tpl and we want to show Search modules on it.

in this case as you said we need 2 files:

 

1- header.tpl

2- blocksearch.php

 

is it right ? if yes please give me more detail...

Share this post


Link to post
Share on other sites

sorry i did your instruction and back office return me some errors:

 

The following module(s) could not be loaded:

 

 

is it possible to discribe your method with a one of prestashop defualt modules ?

 

for example we add new DIV in header.tpl and we want to show Search modules on it.

in this case as you said we need 2 files:

 

1- header.tpl

2- blocksearch.php

 

is it right ? if yes please give me more detail...

I agree, an example would be useful...

I've tried it with ps 1.5.3 and "MyNewHook" wasn't added into the ps_hook table...

 

Edit:

I was wrong, there is a new hook in the ps_hook table...

Edited by doubleD (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

Hi,

 

Sorry for the late answer, I saw that DoubleD saw the hook in ps_hook

Do you still need an example ?

 

I still need the example.if its possible.

i appreciate you for helping me about that.

Share this post


Link to post
Share on other sites

No problem, so as I said, this only work in 1.5.

In one of your template, just add the hook you want

 

For example, index

{hook h='displayMyNewHook'}

 

Then, you can create one (or more) module with this method :

/modules/mymodule/

/modules/mymodule/mymodule.php

 

Content of mymodule.php

 

class MyModule extends Module
{
   function __construct()
   {
       $this->name = 'mymodule';
       $this->tab = 'advertising_marketing';
       $this->author = 'Your name';
       $this->version = '1.0';
       $this->need_instance = 0;

       parent::__construct();

       $this->displayName = $this->l('My Module');
       $this->description = $this->l('Example of module');
   }

   public function install()
   {
   // Here the registerHook method will check if the hook exists, if not it will add it to table ps_hook
       return (parent::install() AND $this->registerHook('displayMyNewHook');
   }

   public function hookDisplayMyNewHook($params)
   {
   return 'myDisplay';
   }
}

 

Now, you have "myDisplay" displayed where you put your hook.

If you want to see this hook in your adminpanel to have the possibility to change order of module which are hooked on.

You will have (unfortunately) to go to you phpmyadmin and set the flag "position" to 1 in the table ps_hook for this hook.

 

Tell me if something is not clear :)

  • Like 7

Share this post


Link to post
Share on other sites

No problem, so as I said, this only work in 1.5.

In one of your template, just add the hook you want

 

For example, index

{hook h='displayMyNewHook'}

 

Then, you can create one (or more) module with this method :

/modules/mymodule/

/modules/mymodule/mymodule.php

 

Content of mymodule.php

 

class MyModule extends Module
{
function __construct()
{
	$this->name = 'mymodule';
	$this->tab = 'advertising_marketing';
	$this->author = 'Your name';
	$this->version = '1.0';
	$this->need_instance = 0;

	parent::__construct();

	$this->displayName = $this->l('My Module');
	$this->description = $this->l('Example of module');
}

public function install()
{
   // Here the registerHook method will check if the hook exists, if not it will add it to table ps_hook
	return (parent::install() AND $this->registerHook('displayMyNewHook');
}

public function hookDisplayMyNewHook($params)
{
   return 'myDisplay';
}
}

 

Now, you have "myDisplay" displayed where you put your hook.

If you want to see this hook in your adminpanel to have the possibility to change order of module which are hooked on.

You will have (unfortunately) to go to you phpmyadmin and set the flag "position" to 1 in the table ps_hook for this hook.

 

Tell me if something is not clear :)

yes it work. We have build custom hook like this way last month for out one great module.

Share this post


Link to post
Share on other sites

The fact that you do not see it in your back office, it's because you have to set the flag "position" to 1 in your table.

(I forgot to set this flag when I coded it).

 

Has this flag been added yet? Justs so i know.

 

tar

Share this post


Link to post
Share on other sites

What do you mean by "added" ?

This flag is existing for a while (even in PrestaShop 1.4). It's just not set to value 1 when you create it by registering a module on it.

Share this post


Link to post
Share on other sites

Hi Fabien

 

what i ment was, when a new hook, is registered in the new way, earlier in the thread you said:

For making the hook appear in you admin panel, you just have to set the flag "position" to 1 in your database.

and then you said

The fact that you do not see it in your back office, it's because you have to set the flag "position" to 1 in your table.

(I forgot to set this flag when I coded it).

 

Were you going to alter the registerHook function to set the positional flag to 1.

 

I know we can use the 'Display Non Positional Hooks' option in the backend

Edited by shoulders (see edit history)

Share this post


Link to post
Share on other sites

Hi,

 

Sorry I did not understand your question at first ^^

I'm not working at PrestaShop anymore (since last july). So no, I am not going to alter the registerHook function.

But you should ask for it on GitHub or on the forge.

Share this post


Link to post
Share on other sites

Hi,

I used this method of creating hooks but I can't display anything in this new created hook. I want display a homeslider in my new hook, but I getting message: "This module cannot be transplanted to this hook."

 

I added my new hook into center of page

 

<!-- Center -->
<div id="center_column" class=" grid_5">
<div class="sliderPlease">
{hook h='sliderHook'}
</div>

 

then I added it into the install method in the homeslider.php

 

if (parent::install() && $this->registerHook('displayHome') && $this->registerHook('actionShopDataDuplication') && $this->registerHook('sliderHook'))

 

And at the bottom of the homeslider.php I added hook function

 

public function sliderHook($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');
}

But It's not working. The hook is installed and I can see it in BO, but I can't hook anything inside it.

Please could somebody tell my what I do wrong????

Edited by xezus (see edit history)

Share this post


Link to post
Share on other sites

Omg, Thanks a lot! You saved me a hours of my live :)

Share this post


Link to post
Share on other sites

Hello Fabien,

 

This is a useful topic.

 

I Want to hook a module in my CMS page how can i do this with the help of your guide here.

If you can guide it would be great...

 

Thanks...

Share this post


Link to post
Share on other sites

Hi smartdatasoft

 

Thankyou for your response i actually followed the post you have give in your response, still i cant make it work i have added a post in the below link the same ill past it here...

 

http://www.prestashop.com/forums/topic/763[spam-filter]hook-modules-into-cms-page/page__st__20

 

any help would be greatly appreciated.

 

Am using PS 1.5.3.1

 

I want hook a module which already installed in home page and i have duplicated the module uploaded into the modules directory.

 

I followed exactly the same steps mentioned here in this post as followes

 

#1. Created a hook entry in PS_Hook table (HOOK_DESIGNMYSHIRT)

 

#2. In cms.tpl file from Module/Mymodule/cms.tpl i added the following

 

{if ($cms->link_rewrite == 'designmyshirt')}

{$HOOK_DESIGHNMYSHIRT}

{/if}

 

#3. Im cms.php file from the root directory i added the following

 

 

$smarty->assign(array(

'cms' => $cms,

'HOOK_DESIGHNMYSHIRT' => Module::hookExec('designmyshirt'), // Custom hook for mycmspage

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

));

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

 

#4. In the modules folder the module php file mymodule.php i added the following

 

public function install(){

if (parent::install() && $this->registerHook('HOOK_DESIGHNMYSHIRT'))

 

 

after at the end of this same file i added the below function

 

function hookdesignmyshirt($params)

{

if ($xml = $this->_xml)

{

global $cookie, $smarty;

$smarty->assign(array(

'xml' => $xml,

'title' => 'title_'.$cookie->id_lang,

'text' => 'text_'.$cookie->id_lang

));

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

}

return false;

}

 

After this i installed the module and checked in the BO position. the module is displayed in the hook in BO

When i check the CMS page nothing is displayed even if i configure the module from BO.

 

I checked the Apache error log i get this following error

 

Notice: Undefined index: HOOK_DESIGHNMYSHIRT in G:\\WAMP Server\\wamp\\www\\rave\\cache\\smarty\\compile\\e2fae568d255bdaa47e61a9405a623865dd4d436.file.cms.tpl.php on line 40, referer: http://localhost/rav...70f78b7d317be98

 

I want this module to be placed in center of the CMS page...

 

Have i did everything correctly please help me to solve this issue....

 

 

Thanks....

Share this post


Link to post
Share on other sites

Hi Kalai,

 

If you're on PrestaShop 1.5, you do not have to create an entry in ps_hook and you don't have to make modification in cms.php.

You just have to follow what I'm saying on my differents posts in this topic

- Add your hook in cms.tpl {hook h='designMyShirt'}

- Then in your module, add the registerHook('designMyShirt')

- Create in your module the method hookDesignMyShirt()

Share this post


Link to post
Share on other sites

And about your error (even if you did not use the right way), your problem might comme the fact you wrote

$this->registerHook('HOOK_DESIGHNMYSHIRT') instead of $this->registerHook('designmyshirt')

Share this post


Link to post
Share on other sites

No problem, so as I said, this only work in 1.5.

In one of your template, just add the hook you want

 

For example, index

{hook h='displayMyNewHook'}

 

Then, you can create one (or more) module with this method :

/modules/mymodule/

/modules/mymodule/mymodule.php

 

Content of mymodule.php

 

class MyModule extends Module
{
function __construct()
{
	$this->name = 'mymodule';
	$this->tab = 'advertising_marketing';
	$this->author = 'Your name';
	$this->version = '1.0';
	$this->need_instance = 0;

	parent::__construct();

	$this->displayName = $this->l('My Module');
	$this->description = $this->l('Example of module');
}

public function install()
{
   // Here the registerHook method will check if the hook exists, if not it will add it to table ps_hook
	return (parent::install() AND $this->registerHook('displayMyNewHook');
}

public function hookDisplayMyNewHook($params)
{
   return 'myDisplay';
}
}

 

Now, you have "myDisplay" displayed where you put your hook.

If you want to see this hook in your adminpanel to have the possibility to change order of module which are hooked on.

You will have (unfortunately) to go to you phpmyadmin and set the flag "position" to 1 in the table ps_hook for this hook.

 

Tell me if something is not clear :)

 

hi fabien , after awhile i did your instruction and it works fine...thank you

but i have one unknown problem

for example made some changes to blockreinsurance module and hook it to new hook that its made with your instruction , but CSS doesn't load with new hook!

as you know css load with this line :

 

$this->context->controller->addCSS($this->_path.'style.css', 'all');

 

it works properly with Footer Hook ( and other hooks too ) but when i use your method css doesnt load and must to define css codes to global css.

 

i add this div to footer.tpl :

 

<div class="bankicon">{hook h='BankHook'}</div>

 

and this is detail of module php :

 

 

public function install()

{

return parent::install() &&

$this->installDB() &&

Configuration::updateValue('blockbankicon_nbblocks', 5) &&

$this->registerHook('BankHook') && $this->installFixtures();

}

 

 

public function hookBankHook($params)

{

 

// Check if not a mobile theme

if ($this->context->getMobileDevice() != false)

return false;

 

$this->context->controller->addCSS($this->_path.'style.css', 'all');

if (!$this->isCached('blockbankicon.tpl', $this->getCacheId()))

{

$infos = $this->getListContent($this->context->language->id);

$this->context->smarty->assign(array('infos' => $infos, 'nbblocks' => count($infos)));

}

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

}

 

what you think about this issue ?

Edited by the_raven (see edit history)

Share this post


Link to post
Share on other sites

Hi Raven,

 

For what I remember addCSS and addJS only works in hookHeader for 1.4

The loop which write css and js inclusion is in header.tpl and it is displayed before others hooks are called.

 

But I thought it should work on 1.5 since a layout is present.

I will test it and come back to you.

  • Like 1

Share this post


Link to post
Share on other sites

Hi Raven,

 

For what I remember addCSS and addJS only works in hookHeader for 1.4

The loop which write css and js inclusion is in header.tpl and it is displayed before others hooks are called.

 

But I thought it should work on 1.5 since a layout is present.

I will test it and come back to you.

 

thank you man..i appreciate you spending time for us..

 

but as i said, addCSS work's in 1.5 and module load css when i use other hooks , but problem occure only with new Hook that i've created with new method..

 

for example in this sample :

public function hookFooter($params)

{

css load correctly...

Edited by the_raven (see edit history)

Share this post


Link to post
Share on other sites

I'm also having problem with this new way of adding hooks. For example, when adding Homeslider to a new hook everything is working great except that no .css or .js files gets added. I can edit the .tpl files and see the changes so that works as it should, but when I look at the source code of the page I don't see the .css or .js files.

 

I'm using the below method of adding files which works fine using the old way of adding hooks.

 

 $this->context->controller->addCSS($this->_path.'flexslider.css');
 $this->context->controller->addJS($this->_path.'js/jquery.flexslider-min.js');
 $this->context->controller->addJS($this->_path.'js/homeslider.js');
 return $this->display(__FILE__, 'homeslider.tpl', $this->getCacheId());

Share this post


Link to post
Share on other sites

I'm also having problem with this new way of adding hooks. For example, when adding Homeslider to a new hook everything is working great except that no .css or .js files gets added. I can edit the .tpl files and see the changes so that works as it should, but when I look at the source code of the page I don't see the .css or .js files.

 

I'm using the below method of adding files which works fine using the old way of adding hooks.

 

 $this->context->controller->addCSS($this->_path.'flexslider.css');
 $this->context->controller->addJS($this->_path.'js/jquery.flexslider-min.js');
 $this->context->controller->addJS($this->_path.'js/homeslider.js');
 return $this->display(__FILE__, 'homeslider.tpl', $this->getCacheId());

 

Hello piqsel,

 

You should move the css and js in the header hook

 

/**
* Header hook
*/
 public function hookHeader($params)
 {
  global $smarty;
  Tools::addCSS(($this->_path).'flexslider.css', 'all');
  Tools::addJS(($this->_path).'js/jquery.flexslider-min.js', 'all');
  Tools::addJS(($this->_path).'js/homeslider.js', 'all');
 }

Edited by l2c2 (see edit history)

Share this post


Link to post
Share on other sites
but as i said, addCSS work's in 1.5 and module load css when i use other hooks , but problem occure only with new Hook that i've created with new method..

 

Hi everybody,

 

after creating the hook the "new way" I got the same problem as Raven,

 

in details:

I created a new hook for blockreinsurance in template -->

{hook h='BeforeFooter'}

add to install -->

&& $this->registerHook('BeforeFooter');

 

and then defined the function:

public function hookBeforeFooter($params)
{
return $this->hookFooter($params);
}

 

the problem is blockreinsurance.css is not being added,

Share this post


Link to post
Share on other sites

I used the new method to add the "block contact info" module and it works 100% ,

css is found in header (as usual);

 

so it probably depends from module to module on how the css is brought in...

 

anyway these css problems can be easily worked out,

I recommend this procedure for creating hooks quickly,

awesome Topic

Share this post


Link to post
Share on other sites
Hello piqsel, You should move the css and js in the header hook
 /** * Header hook */ public function hookHeader($params) { global $smarty; Tools::addCSS(($this->_path).'flexslider.css', 'all'); Tools::addJS(($this->_path).'js/jquery.flexslider-min.js', 'all'); Tools::addJS(($this->_path).'js/homeslider.js', 'all'); } 

 

Hi l2c2 and thank you for your help.

 

You're right, it seems that the css and js files only gets added when they're in the headerHook. So what is the recommended way if you for example want to place the Top horizontal menu module in a custom hook? This module adds css and js files in hookDisplayTop, so should one edit the module by creating a hookHeader or create a custom hook the old way? :)

Share this post


Link to post
Share on other sites

No problem, so as I said, this only work in 1.5.

In one of your template, just add the hook you want

 

For example, index

{hook h='displayMyNewHook'}

 

Then, you can create one (or more) module with this method :

/modules/mymodule/

/modules/mymodule/mymodule.php

 

Content of mymodule.php

 

class MyModule extends Module
{
function __construct()
{
	$this->name = 'mymodule';
	$this->tab = 'advertising_marketing';
	$this->author = 'Your name';
	$this->version = '1.0';
	$this->need_instance = 0;

	parent::__construct();

	$this->displayName = $this->l('My Module');
	$this->description = $this->l('Example of module');
}

public function install()
{
   // Here the registerHook method will check if the hook exists, if not it will add it to table ps_hook
	return (parent::install() AND $this->registerHook('displayMyNewHook');
}

public function hookDisplayMyNewHook($params)
{
   return 'myDisplay';
}
}

 

Now, you have "myDisplay" displayed where you put your hook.

If you want to see this hook in your adminpanel to have the possibility to change order of module which are hooked on.

You will have (unfortunately) to go to you phpmyadmin and set the flag "position" to 1 in the table ps_hook for this hook.

 

Tell me if something is not clear :)

 

I followed the step above and got an error in my modules page at back office

 

The following module(s) could not be loaded::

  • rajamodule (parse error in /modules/rajamodule/rajamodule.php)
  • rajamodule (class missing in /modules/rajamodule/rajamodule.php)

 

This is the hook I created in 404.tpl

 

{hook h='404captainhook'} 

 

This is the module I created in module/rajamodule/rajamodule.php

 

class MyModule extends Module
{
function __construct()
{
	$this->name = 'mymodule';
	$this->tab = 'advertising_marketing';
	$this->author = 'Your name';
	$this->version = '1.0';
	$this->need_instance = 0;

	parent::__construct();

	$this->displayName = $this->l('My Module');
	$this->description = $this->l('Example of module');
}

public function install()
{
	   // Here the registerHook method will check if the hook exists, if not it will add it to table ps_hook
	return (parent::install() AND $this->registerHook('404captainhook');
}

public function hook404captainhook($params)
{
	   return 'myDisplay';
}
}

 

Can anyone help?


Share this post


Link to post
Share on other sites

Hi Syntaxed,

 

First of all, you should name your module like your directory.

Your module is in the following file :

/modules/rajamodule/rajamodule.php

So your class declaration should be :

class RajaModule extends Module

 

About the parse error, it's my fault, I forgot a ")" in my example.

But parse error is a very common PHP error, you should have been able to detect yourself :P

The line which contains the error is this one :

return (parent::install() AND $this->registerHook('404captainhook');

 

You should add a ) at the end of the line

return (parent::install() AND $this->registerHook('404captainhook'));

Share this post


Link to post
Share on other sites

Hi Fabian,

 

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

Share this post


Link to post
Share on other sites

I added  a new hook with the new way:

{hook h='LeftFooter'}

 

and then on the module (block contact info)

i added 

&& $this->registerHook('LeftFooter')

 

and

public function hookLeftFooter($params)
    {
    return $this->hookFooter($params);
    }

 

And it had worked perfectly

 

but...

 

recently I changed my shop url directory folder

and I couldn't get the module template to update in anyway

--while every other module was working correctly......

 

 

To make it work I had to eliminate it and reinstall,

no big deal but still

it behaved differently than other module+hooks

  • Like 1

Share this post


Link to post
Share on other sites

Hi,

Very strange, changing your shop url should not impact on module template.
Are you sure it was not a cache problem or anything else like that ?

I'll make a test to check this.

Fabien

Share this post


Link to post
Share on other sites

 I went over it again,

and now it's working correctly,

 

maybe your right...

 

thanks anyway

Share this post


Link to post
Share on other sites

Hello everyone,

 

I have a problem - i want to add user info module to newly created hook, but prestashop says it can't be moved to this hook. Any ideas?

Edited by malyo (see edit history)

Share this post


Link to post
Share on other sites

in your blockuserinfo.php you need to modify public function...

find

public function hookTop($params){  ........  ........  ........}

and change it to

public function hookNEWHOOK($params) { ........... .. . . . . .}

Your hook should work now,

 

---

you can also find another hint to visualize your new hook in the backoffice/module/position ,

read  Fabien's post #21

Edited by maio (see edit history)

Share this post


Link to post
Share on other sites

Does it WORK properly? If so just change the css of the newsletter as I see that everything else looks good!

Share this post


Link to post
Share on other sites

Does it WORK properly? If so just change the css of the newsletter as I see that everything else looks good!

Thank you very much for the swift reply

It does work properly the only problem is the css which i could not figure out what to enter or even where to enter it.I spent three hours on it and in the end i left it looking that way. i was using firebug

 

I noticed somewere in this thread you had said something about the css

http://www.prestashop.com/forums/topic/241012-solvedhow-do-i-move-the-newsletter-block-to-the-footer/

could you please tell me what i need to write in the css files.

Share this post


Link to post
Share on other sites

just right click -> inspect element -> check where the corresponding css is located & play with the settings for the desired result -> just copy&paste the changes in the file and refresh

Share this post


Link to post
Share on other sites

Hi Techies,

 

I am using Prestashop version 1.5.6.2. In my product-list.tpl I have this code

<div id="prod_list">{hook h='myOwnHook' idproduct=$product.id_product}</div>

In my module folder myownhook.php file contains

public function hookMyOwnHook($params)
{
	$id_product = $params['idproduct'];
	
	if($id_product)
	{
		$product_info = $id_product;
		$smarty->assign('product_info', $product_info); 
		return $this->display(__FILE__, 'myownhook.tpl');
	}
		
}

In my myownhook.tpl file

<div id="myownhook">{$product_info}</div> 

I am not getting anything on my product-list.tpl.

Edited by mdusamaansari (see edit history)

Share this post


Link to post
Share on other sites

hello

does the $id_product variable exist after $id_product = $params['idproduct'];

can you please verify it?

Share this post


Link to post
Share on other sites

hello

does the $id_product variable exist after $id_product = $params['idproduct'];

can you please verify it?

 

Hi Vekia,

 

The .tpl file contains

<div id="prod_list">{hook h='myOwnHook' idproduct=$product.id_product}</div>

I hope $product.id_product contains the variable value.

Share this post


Link to post
Share on other sites

Hello,  have face this kind of issue. IF you passed product id and on custom hook . It only work on product-list.tpl

 

If you put this on any home page module and it is cached there wrong data comes. 

I have do this to show product ratting. If there is no ratting on some product , it show the previous product ratting :(

 

 

Here is my code

 {hook h='displaySdsAfterProductName' idproduct=$product.id_product}

and bellow code is run on php file

  public function hookDisplaySdsAfterProductName($params)

    {        

    
 
    
        global $smarty ;           

           if(!isset($params['idproduct']) OR empty($params['idproduct']))

            return 'No ID';
        
    require_once(_PS_MODULE_DIR_.'/productcomments/ProductComment.php');
    require_once(_PS_MODULE_DIR_.'/productcomments/ProductCommentCriterion.php');
 
    $id_product = $params['idproduct'];
    $product_average = 0;
 
    $grades = ProductComment::getAveragesByProduct($id_product, $this->context->language->id);
    $criterions = ProductCommentCriterion::getByProduct($id_product, $this->context->language->id);
    $grade_total = 0;
    
        if (count($grades) > 0)
    {
        foreach ($criterions as $criterion)
        {
            if (isset($grades[$criterion['id_product_comment_criterion']]))
            {
                $grade_total += (float)($grades[$criterion['id_product_comment_criterion']]);
            }
        }
     
        $product_average = $grade_total / count($criterions);
    }

$this->context->smarty->assign('average_total', (int)$product_average);

 
 
      
        
        return $this->display(__FILE__,'views/templates/front/single_product_rating.tpl');

    }
    

I used this to show product ratting in my Sellya theme.

Share this post


Link to post
Share on other sites

is it possible to put in a hook to call an existing mod? my index is mostly custom html, but i want to insert the featured products module in there, how would i go about that?

Share this post


Link to post
Share on other sites

you can't call module, you can call only hooks

so create custom hook, attach there your module, then call this hook

Share this post


Link to post
Share on other sites
Hi,

I followed the steps to create new hooks described by Fabien. Everything works on localhost but not on-line. The module  is not loaded in the new hook... 

Can you help me?

Thanks!

Share this post


Link to post
Share on other sites

I tried to create my custom module and hook using the following code but when i gp to module page i get the following error, in italian
 

Il modulo seguente (s) non è stato possibile caricare:
  1. mymodule (errore di analisi in /modules/mymodule/mymodule.php)
  2. mymodule (classe mancante in /modules/mymodule/mymodule.php)

It says the module has not been loaded.

1) analisys error

2) missing class

 

Any idea of the problem ?

 
class MyModule extends Module
{
function __construct()
{
$this->name = 'mymodule';
$this->tab = 'advertising_marketing';
$this->author = 'Your name';
$this->version = '1.0';
$this->need_instance = 0;

parent::__construct();

$this->displayName = $this->l('My Module');
$this->description = $this->l('Example of module');
}

public function install()
{
     // Here the registerHook method will check if the hook exists, if not it will add it to table ps_hook
return (parent::install() AND $this->registerHook('displayMyNewHook');
}

public function hookDisplayMyNewHook($params)
{
     return 'myDisplay';
}
}

Share this post


Link to post
Share on other sites

Hi Yoeba,

 

Can you post your code ?

Maybe I'll be able to help you :)

 

 

Hi Gfstudio,

 

I'm sure you figured out what your problem was (since your post was 6 month ago).

But in fact you just forgot a )

return (parent::install() AND $this->registerHook('displayMyNewHook');

should have been

return (parent::install() AND $this->registerHook('displayMyNewHook'));

Share this post


Link to post
Share on other sites

Hi Fabien Serny

 

Recently I bought a module to show delivery dates and time-frame slots for customers it works well in front (website) but when I made a custom hook and and tried to call the hook into back-end admin , manual new order it does not shows up.

 

The hook installed in database ps_hooks perfectly

 

here is the code i used to install

----------------------------------------------------------

 

 public function install()
    {
        if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
            $before_carrier = method_exists('Hook', 'get') && Hook::get('beforeCarrier');
        } else {
            $before_carrier = true;
        }
 
        if (!$this->samdha_tools->executeSQLFile(self::INSTALL_SQL_FILE)
            || !parent::install()
            || !($before_carrier?$this->registerHook('beforeCarrier'):true)
            || !$this->registerHook('footer')
            || !$this->registerHook('header')
            || !$this->registerHook('adminOrder')
|| !$this->registerHook('GoDate')
            || (version_compare(_PS_VERSION_, '1.5.0.0', '>=')?!$this->registerHook('displayPDFInvoice'):false)
            || (version_compare(_PS_VERSION_, '1.5.0.0', '>=')?!$this->registerHook('displayPDFDeliverySlip'):false)
            || !$this->registerHook('newOrder')) {
            return false;
        }
        return true;
    }
 
 
public function hookGoDate($params)
{
return $this->display(__FILE__, 'deliverydays.tpl');
}

Share this post


Link to post
Share on other sites
post-705830-0-00346400-1449654013_thumb.png
 
 
Ok Luckily i managed to get hook into form.tpl, but date selection is not active...is it jquery issue??

 

see the attachment

Share this post


Link to post
Share on other sites

no error reported but i can't select the date in backend whereas i can select the date and timeframe from front end while checking out 

 

I will PM u the code 

Share this post


Link to post
Share on other sites

Bonjour Fabien,

Ca fait 2 fois que ma boutique saute et le pb que tu soulèves ressemble au mien... enfin je crois. En fait dans le back office j'ai voulu tester la remise sur un groupe de clients. Je me suis mis donc dedans avec mon adresse d'administrateur et lorsque j'ai validé j'ai eu un étrange message rouge. Comme c'est pas le 1er que je vois, j'ai quitté la session et lorsque je me suis connecté sur le site et rentré mes identifiants/MDP, le site a sauté et pour TOUS les clients qui se loguent. Par contre pour les visiteurs, le site paraît normal.

 

Du coup je suis retourné sur le backoffice et j'ai remis les mêmes paramètres que j'avais à la base dans ma fiche clients et hop le site refonctionne.

Voici le type de lignes que j'avais sur ma home lorsque le site avait sauté: "Undefined index:HOO_BLOCKPOSITION1 in /homepages/42/...." " Notice:Trying to get property of non-object in/homepages/42/..."

Et j'ai ensuite le même genre pour le HOOK_BLOCKFOOTER1 et HOOK_BLOCKFOOTER3

Merci de ton aide Fabien

Share this post


Link to post
Share on other sites

×

Important Information

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