Jump to content
vblanch

[MODULE] Hook Manager

Recommended Posts

Hi everyone.

Together with a partner, we recently developed a new theme for an online store. To do this we needed to introduce new hooks in the store, design themes . While programming it , we realized that the hooks in PrestaShop is highly dependent on modules (eg calling the function "registerHook" , restart the module, etc... ) And also sometimes you have to touch the database if you want the new hooks to display in "Positions" and be able to associate modules to them.

So I developed a module that lets you create, edit and remove hooks in an easy way from the control panel of Prestashop. This module also allows you to show or hide the hooks in positions.
 

The module is completely free and is released under the GPL2 license.
 

It has been developed for Prestashop 1.5.x version, I didn't try it on a 1.4.x, if I see that people are interested I may do the adaptation to these versions.

 

*EDIT: I addapted the code so now it's compatible with 1.4.x and even maybe with 1.3.x (didn't try), just download v1.0.3 of the module or higher*

The module is multilingual.

If this module really makes your life easier and you want to support my work you can make a donation, in the configure screen of the module it's specified how.
 

Thank you!

Installation and use :

1. Put the "hookmanager" folder in "modules" .

2. Enable the module in Modules (control panel) .

3. In Modules, click the "Configure" button on the Hooks Manager module.

4. Create, modify or delete hooks.

Note : You can leave the module activated once done (it's status does not affect the hooks you've created / modified / deleted).

 

You can alse see the code or fork it in GitHub: https://github.com/vblanch/hookmanager_ps_module

 

Version History:

1.0.0-1.0.1: Initial release/some typos fixed.

Update 1.0.2: Changed "Create" for "New Hook" and the german translation is now correct, thanks to eleazar!

1.0.3 Added compatibility with Prestashop 1.4.x, maybe 1.3.x but I didn't try, you are free to test it. Also hooks are sorted alphabetically now. Some debug code removed, some typos in comments fixed.

1.0.4 Removed translations that I'm unable to keep updated, and added compatibility with Prestashop 1.6.x. Now it's possible to set the title and the description of the hook!

post-746300-0-36980600-1389224739_thumb.jpg

hookmanager_ps_module_1.0.4.zip

Edited by vblanch

Share this post


Link to post
Share on other sites

Well this is an excelent module. Just what I was looking for. If it does what i think it does :)

 

Going to install it right now.

Thx for making the module free.

Share this post


Link to post
Share on other sites

Well this is an excelent module. Just what I was looking for. If it does what i think it does :)

 

Going to install it right now.

Thx for making the module free.

 

Hi there abondares,

you are welcome. Hope it's useful for you.

If you have any suggestions to improve it just tell me ;)

Share this post


Link to post
Share on other sites

Hello,

 

I am interested in this module too. Is it possible to make the changes and adapt it to PS 1.4.x ?

 

Kind regards,

 

Marianna

Share this post


Link to post
Share on other sites

Hello,

 

I am interested in this module too. Is it possible to make the changes and adapt it to PS 1.4.x ?

 

Kind regards,

 

Marianna

 

Hi Marianna,

I just added compatibility with 1.4.x.

Give it a try, it should work.

Regards

Share this post


Link to post
Share on other sites

Bonjour et merci pour ce module. depuis une mise à niveau en 1.5.6.2 depuis 1.5.6.1 j' ai ce bug.

 

! ) Notice: Undefined variable: html in C:\wamp\www\monsite\modules\hookmanager\hookmanager.php on line 153 Call Stack # Time Memory Function Location 1 0.0014 403168 {main}( ) ..\index.php:0 2 0.1737 7560312 DispatcherCore->dispatch( ) ..\index.php:53 3 0.2995 12824840 ControllerCore->run( ) ..\Dispatcher.php:348 4 0.8000 15937248 AdminModulesControllerCore->postProcess( ) ..\Controller.php:158 5 0.8001 15938848 AdminModulesControllerCore->postProcessCallback( ) ..\AdminModulesController.php:811 6 0.8099 16066264 HookManager->getContent( ) ..\AdminModulesController.php:685 7 0.8099 16066400 HookManager->displayForm( ) ..\hookmanager.php:139

 

Quelqu'un pourrait il m'aider .Merci

Share this post


Link to post
Share on other sites

Does it work in Prestashop 1.6 ?

 

It would be great if it works in 1.6

 

Give it a try, it should work now in PS 1.6!

 

Donations are highly appreciated :-)

Share this post


Link to post
Share on other sites

Hi, Greetings

I am having an error installing the module and when to I want to edit. Here a screenshot of the error:

Is an updated PS 1.5 to 1.6.0.8 store, the store works well. Install a clean version in PS 1.6.0.8 and this not get the bug. Any idea what It could be?

 

post-53632-0-47301600-1406594577_thumb.jpg

Share this post


Link to post
Share on other sites

Hi, Greetings

 

I am having an error installing the module and when to I want to edit. Here a screenshot of the error:

 

Is an updated PS 1.5 to 1.6.0.8 store, the store works well. Install a clean version in PS 1.6.0.8 and this not get the bug. Any idea what It could be?

 

I get the same error. I am on fresh PS 1.6.0.8 install.

 

edit:

I think this is caused because $html variable has a Concatenation assignment (.=) in both if cases (either line 162 or 165). 

 

I initialized $html on line 160 by setting $html = null; and the message is gone.

 

Edited by HaCos

Share this post


Link to post
Share on other sites

Give it a try, it should work now in PS 1.6!

 

Donations are highly appreciated :-)

 

Can you explain how exacly does it work?

I created a a new hook and it is succefully listed in positions. I face 2 issues: 

1. No matter which module i try to transplant to this hook, it doesnt work. I get the error msg : This module cannot be transplanted to this hook.

2. How will this hook show up in template? Dont we need to add the hook name in the .tpl files in order to get loaded there?

 

Regards,

C

Share this post


Link to post
Share on other sites

Hi, Greetings

 

I am having an error installing the module and when to I want to edit. Here a screenshot of the error:

 

Is an updated PS 1.5 to 1.6.0.8 store, the store works well. Install a clean version in PS 1.6.0.8 and this not get the bug. Any idea what It could be?

 

Hi there,

first of all, thanks for using it and for the feedback. Do not worry about the "Notice" messages. They are more like warnings, no real errors.

 

I get the same error. I am on fresh PS 1.6.0.8 install.

 

edit:

I think this is caused because $html variable has a Concatenation assignment (.=) in both if cases (either line 162 or 165). 

 

I initialized $html on line 160 by setting $html = null; and the message is gone.

 

You are right, initializing the variable will fix the notice. I will push that change into the next version.

 

Can you explain how exacly does it work?

I created a a new hook and it is succefully listed in positions. I face 2 issues: 

1. No matter which module i try to transplant to this hook, it doesnt work. I get the error msg : This module cannot be transplanted to this hook.

2. How will this hook show up in template? Dont we need to add the hook name in the .tpl files in order to get loaded there?

 

Regards,

C

 

1. You create the hook for the modules, however you must add extra code to the modules themselves in order to be able to be added to this hook. For instance, if your hook is called "test", you must have a function in the module you want to add to the hook called "hookTest". You can copy the inner workings of that function from another on the same module (for example if it has a hookTop function or similar).

 

2. Hook will show in template if you call it. There's special smarty code in order to "call" a hook. Please take a look at the header.tpl or footer.tpl in your theme, you should find something like "{$HOOK_HEADER}". In order to call the hook, you must add other extra code too. Here is an example: http://www.prestashop.com/forums/topic/203786-to-call-home-hook-in-all-other-template-files-in-prestashop/

 

I hope this all clarifies things a bit :)

 

Cheers

Share this post


Link to post
Share on other sites

You are right, initializing the variable will fix the notice. I will push that change into the next version.

 

Already created a pull request :)

 

1. You create the hook for the modules, however you must add extra code to the modules themselves in order to be able to be added to this hook. For instance, if your hook is called "test", you must have a function in the module you want to add to the hook called "hookTest". You can copy the inner workings of that function from another on the same module (for example if it has a hookTop function or similar).

 

2. Hook will show in template if you call it. There's special smarty code in order to "call" a hook. Please take a look at the header.tpl or footer.tpl in your theme, you should find something like "{$HOOK_HEADER}". In order to call the hook, you must add other extra code too. Here is an example: http://www.prestashop.com/forums/topic/203786-to-call-home-hook-in-all-other-template-files-in-prestashop/

 

I hope this all clarifies things a bit :)

 

Cheers

Thanks for the info, i ll give a try and let you know.

 

Regards,

C

Share this post


Link to post
Share on other sites

I get the same error. I am on fresh PS 1.6.0.8 install.

 

edit:

I think this is caused because $html variable has a Concatenation assignment (.=) in both if cases (either line 162 or 165). 

 

I initialized $html on line 160 by setting $html = null; and the message is gone.

 

Thanks Hacos for change, works for me.

 

 

 

Hi there,

first of all, thanks for using it and for the feedback. Do not worry about the "Notice" messages. They are more like warnings, no real errors.

 

 

Thanks

Share this post


Link to post
Share on other sites

I just updated the code, now the "$html" notice shouldn't show anymore. So if you don't want to edit the code just download the file and overwrite the old module.

 

Cheers

Share this post


Link to post
Share on other sites

I just updated the code, now the "$html" notice shouldn't show anymore. So if you don't want to edit the code just download the file and overwrite the old module.

 

Cheers

 

Ready! Overwritten. :)

Share this post


Link to post
Share on other sites

Hello I have presta shop 6 I have installed your module but when I am going in themeconfigurator I can not see the hook which I name profooter, could you tell me what do I have to do?

Thanks

Marina

Share this post


Link to post
Share on other sites

Hi vblanch,

thanks a lot for your contribution.

 

Can you please explain step by step how to add a new hook (for example, in my need, in product.tpl page)

 

Thanks in advance

 

 

Hi there,

first of all, thanks for using it and for the feedback. Do not worry about the "Notice" messages. They are more like warnings, no real errors.

 

 

You are right, initializing the variable will fix the notice. I will push that change into the next version.

 

 

1. You create the hook for the modules, however you must add extra code to the modules themselves in order to be able to be added to this hook. For instance, if your hook is called "test", you must have a function in the module you want to add to the hook called "hookTest". You can copy the inner workings of that function from another on the same module (for example if it has a hookTop function or similar).

 

2. Hook will show in template if you call it. There's special smarty code in order to "call" a hook. Please take a look at the header.tpl or footer.tpl in your theme, you should find something like "{$HOOK_HEADER}". In order to call the hook, you must add other extra code too. Here is an example: http://www.prestashop.com/forums/topic/203786-to-call-home-hook-in-all-other-template-files-in-prestashop/

 

I hope this all clarifies things a bit :)

 

Cheers

Share this post


Link to post
Share on other sites

Hi vblanch,

thanks a lot for your contribution.

 

Can you please explain step by step how to add a new hook (for example, in my need, in product.tpl page)

 

Thanks in advance

 

Hi Jager,

what my module does is to create an entry in the database for the hook, so you don't have to do it yourself.

Then you can attach your modules to the hook. Once that is done, you must call the hook in your TPL.

 

More or less, if your hook is called "jager" you should call it like this: {$HOOK_JAGER}

 

I may have forgotten something but I think that's all you should need to make the hook work. Just in case, there's quite complete guide by Nemo in here: http://nemops.com/a-deeper-look-at-prestashop-hooks/#.VKlZzHsYG6Q

 

Cheers.

Share this post


Link to post
Share on other sites

Hi Jager,

what my module does is to create an entry in the database for the hook, so you don't have to do it yourself.

Then you can attach your modules to the hook. Once that is done, you must call the hook in your TPL.

 

More or less, if your hook is called "jager" you should call it like this: {$HOOK_JAGER}

 

I may have forgotten something but I think that's all you should need to make the hook work. Just in case, there's quite complete guide by Nemo in here: http://nemops.com/a-deeper-look-at-prestashop-hooks/#.VKlZzHsYG6Q

 

Cheers.

 

Thanks for you help Cheers,

 

In pratice, what I want to do is to create an hook in the product page (product.tpl), just before long description where to put the crosseling (and other) module. This module (crosseling) is now diplayed on the footer of the product page, but we need to display it next the product details and before long description.

 

The following solution is correct?

 

1) I create the hook with your module called "test"

 

2) in file crossselling.php I put in the following code:

$smarty->assign(array(
        'TEST' => Module::hookExec('test')));
$smarty->display(_PS_THEME_DIR_.'product.tpl');

3) in template file "product.tpl" where I want the hook will be displayed I put:

{$HOOK_TEST}

 

Is correct?

Share this post


Link to post
Share on other sites

Thanks for you help Cheers,

 

In pratice, what I want to do is to create an hook in the product page (product.tpl), just before long description where to put the crosseling (and other) module. This module (crosseling) is now diplayed on the footer of the product page, but we need to display it next the product details and before long description.

 

The following solution is correct?

 

1) I create the hook with your module called "test"

 

2) in file crossselling.php I put in the following code:

$smarty->assign(array(
        'TEST' => Module::hookExec('test')));
$smarty->display(_PS_THEME_DIR_.'product.tpl');

3) in template file "product.tpl" where I want the hook will be displayed I put:

{$HOOK_TEST}

 

Is correct?

 

 

Hi there,

 

read this too: http://doc.prestashop.com/display/PS14/Understanding+and+using+hooks

 

Steps that I would do:

 

1. Create the hook, let's say "test" with the HookManager module (it saves you from having to put SQL code into the database like the Insert they make in the documentation I liked to you before).

 

2. Register the hook on your module:

public function install()
{
    //... other code here for your module
    return parent::install() && $this->registerHook('Test');
}

3. Create the callback for the new hook in your module:

public function hookTest($params)
{
//... whatever your module has to do in here, like displaying a TPL
}

I strongly suggest that you take a good look at the modules shipped with PrestaShop, find a similar one to the one you are trying to make and take a look at their hook callbacks and such. You can even use their code as a basis for your module.

 

And finally all you have to do is trial and error, like in all programming :D

 

Cheers,

Víctor

Edited by vblanch

Share this post


Link to post
Share on other sites

hey is this module is compatible with latest prestashop version 1.6.0.11?

 

 

1.0.4 Removed translations that I'm unable to keep updated, and added compatibility with Prestashop 1.6.x. Now it's possible to set the title and the description of the hook!

 

Cheers :D

Share this post


Link to post
Share on other sites

Hi Vblanch,

 

I have a problem with a module, where I have deleted the hooks. the used to have 2 hooks for the following options below.

 

The module name is PagSeguro - its a payment gateway in Brazil.

 

How do I create a new hooks for the 2 options below?

 

Many Thanks.

Rolando

 

Payment - 0 Módulo  [This hook displays new elements on the payment page] (Nome técnico:displayPayment)  

 

Payment return - 0 Módulo (Nome técnico:displayPaymentReturn)

Share this post


Link to post
Share on other sites

 

Hi Vblanch,

 

I have a problem with a module, where I have deleted the hooks. the used to have 2 hooks for the following options below.

 

The module name is PagSeguro - its a payment gateway in Brazil.

 

How do I create a new hooks for the 2 options below?

 

Many Thanks.

Rolando

 

Payment - 0 Módulo  [This hook displays new elements on the payment page] (Nome técnico:displayPayment)  

 

Payment return - 0 Módulo (Nome técnico:displayPaymentReturn)

 

 

Problem resolved. edited file /modules/pagseguro/pagseguro.php between lines 92 and 109 - changed from false to true and vice and versa. Finally could uninstall the module version 1.8 and install version 1.9

 

Now all hooks are back in place, tested an order and payment went thru.

Edited by rasfonseca

Share this post


Link to post
Share on other sites

 

Hi Vblanch,

 

I have a problem with a module, where I have deleted the hooks. the used to have 2 hooks for the following options below.

 

The module name is PagSeguro - its a payment gateway in Brazil.

 

How do I create a new hooks for the 2 options below?

 

Many Thanks.

Rolando

 

Payment - 0 Módulo  [This hook displays new elements on the payment page] (Nome técnico:displayPayment)  

 

Payment return - 0 Módulo (Nome técnico:displayPaymentReturn)

 

 

Hi there Rolando,

I think that the hooks are created by the module itself. You could try re-installing the module and see if it helps.

Otherwise use this module to re-create the hooks with the same name.

Another possibility is to create a dummy PrestaShop, install the module there and see exactly the parameters of the hooks. Then re-create the hooks on your production PrestaShop.

 

Hope it helps!

Problem resolved. edited file /modules/pagseguro/pagseguro.php between lines 92 and 109 - changed from false to true and vice and versa. Finally could uninstall the module version 1.8 and install version 1.9

 

Glad to see you solved it :)

Share this post


Link to post
Share on other sites

Hi Vblanch,

 

This is my issue:

I need to show the smartblogrecentposts in my theme footer.

 

1. First I installed your module, and create a new hook called "posts"

2. In the smartblogrecentposts.php I insert my hook. like this:

 

public function install(){
                if (!parent::install() || !$this->registerHook('leftColumn')
                || !$this->registerHook('displaySmartBlogLeft')
                || !$this->registerHook('posts')
                || !$this->registerHook('actionsbdeletepost')
                || !$this->registerHook('actionsbnewpost')
                || !$this->registerHook('actionsbupdatepost')
                || !$this->registerHook('actionsbtogglepost')
                )
        return false;
                Configuration::updateGlobalValue('smartshowrecentpost',5);
             return true;
        }

 

And insert this line too:

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

 

3. OK i see my hook "posts" and the "smarblogrecentposts" module assigned to my hook in modulepositions.

 

4. Now in my footer.tpl I insert this:

{$HOOK_POSTS}

But nothing is showed. :(

 

I try aswell with {$POSTS} but see the word "Array" in my footer. :(

 

Can you help me please? I missed something?

Share this post


Link to post
Share on other sites

Hi Vblanch,

 

This is my issue:

I need to show the smartblogrecentposts in my theme footer.

 

1. First I installed your module, and create a new hook called "posts"

2. In the smartblogrecentposts.php I insert my hook. like this:

 

public function install(){

                if (!parent::install() || !$this->registerHook('leftColumn')

                || !$this->registerHook('displaySmartBlogLeft')

                || !$this->registerHook('posts')

                || !$this->registerHook('actionsbdeletepost')

                || !$this->registerHook('actionsbnewpost')

                || !$this->registerHook('actionsbupdatepost')

                || !$this->registerHook('actionsbtogglepost')

                )

        return false;

                Configuration::updateGlobalValue('smartshowrecentpost',5);

             return true;

        }

 

And insert this line too:

public function hookposts($params)

            {

                 return $this->hookLeftColumn($params);

            }

 

3. OK i see my hook "posts" and the "smarblogrecentposts" module assigned to my hook in modulepositions.

 

4. Now in my footer.tpl I insert this:

{$HOOK_POSTS}

But nothing is showed. :(

 

I try aswell with {$POSTS} but see the word "Array" in my footer. :(

 

Can you help me please? I missed something?

 

Hello gothw,

 

Try a different name. HOOK_POSTS sounds very generic and might be used already. Follow the steps shown in the module help. 

 

If it doesn't work, try a different name and follow the "traditional" way of doing it with PrestaShop (without modules, tampering with the database).

 

See if this works.

Share this post


Link to post
Share on other sites

Hello Vblanch,

I tried with different name "natur_blog", everything is ok, but still not showed.

 

I take a look to the database and everything looks ok too.

 

I have my module in ps_hook table:

198 natur_blog Natur_blog Latest posts 1

0

 

In ps_hook_module table have the redord to asociate smartblogrecentposts module:

126 1 198 1

 

I called the hook in footer.tpl like this:

{$HOOK_natur_blog}   , also tried {$HOOK_NATUR_BLOG}   and {$NATUR_BLOG}

 

is this ok?

Share this post


Link to post
Share on other sites

Hello Vblanch,

I tried with different name "natur_blog", everything is ok, but still not showed.

 

I take a look to the database and everything looks ok too.

 

I have my module in ps_hook table:

198 natur_blog Natur_blog Latest posts 1

0

 

In ps_hook_module table have the redord to asociate smartblogrecentposts module:

126 1 198 1

 

I called the hook in footer.tpl like this:

{$HOOK_natur_blog}   , also tried {$HOOK_NATUR_BLOG}   and {$NATUR_BLOG}

 

is this ok?

 

Finally works calling the hook like this: {hook h="natur_blog"}

Share this post


Link to post
Share on other sites

Hi, 

 

I have uploaded the module, it is not showing in my back office under modules.

 

I logged into my cPanel and the folders etc are there.

 

How do I find it in my back office under modules?

 

Thanks

Share this post


Link to post
Share on other sites

Hi,

First of all, thanks for the good job and the module. I used for making two column hooks in the footer, but it has not working for me until I changed "displayHeader" by "initHeader" in /override/classes/controller/FrontController.php. Here my code:

<?php 
class FrontController extends FrontControllerCore
{
	public function initHeader()
	{
		if (!self::$initialized)
			$this->init();
			self::$smarty->assign('HOOK_PIE_IZDA', Module::hookExec('displayPieIzquierda'));
		parent::initHeader();		

		if (!self::$initialized)
			$this->init();
			self::$smarty->assign('HOOK_PIE_DCHA', Module::hookExec('displayPieDerecha'));
		parent::initHeader();		
	}
}

I read somewhere that displayHeader is deprecated. Well, now, I don't know why, but it works for me :P

 

Salú. (Sorry my bad English)

Share this post


Link to post
Share on other sites

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

×