Jump to content

How to call/execute a Hook from a custom module ?


rayrayrugby

Recommended Posts

To call a hook inside a module, you can use:

Hook::exec('displayBackOfficeHeader', array())

To call it in a tpl file, you should first assign it to a smarty variable:

$this->context->smarty->assign('displayBackOfficeHeader', Hook::exec('displayBackOfficeHeader', array())); 

But you should be careful with this, because for example if you have javascript code - it will be added twice.

  • Like 1
Link to comment
Share on other sites

it seems to work except for the .tpl of my module, wich should be displayed when the hook backofficefooter is executing. Maybe because I don't use this method ? : 

 

(And sorry the Hook is "displaybackofficefooter")

 

 

 

$this->context->smarty->assign('displayBackOfficeFooter', Hook::exec('displayBackOfficeFooter', array())); 
Edited by rayrayrugby (see edit history)
Link to comment
Share on other sites

To be more exact, for the moment what I want is display on backoffice pages a simple js alert that I've created inside of a tpl file. So to do this i used the hooks "actionvalidateorder" and "displaybackofficefooter" like that : 

 

public function hookactionValidateOrder($params)
{
    Hook::exec('displayBackOfficeFooter', array());
}
 
public function hookdisplayBackOfficeFooter($params)
{
    return $this->display(__FILE__, 'test.tpl');
}
 
But when I make an order nothing happens, I really don't know why..
 
Link to comment
Share on other sites

I am not sure I completely understand what you are trying to accomplish.

 

I believe you want a javascript code to execute in BO when an order is placed in FO.

If so, then this is not the correct approach.

 

Connect your module only to hookdisplayBackOfficeFooter and here display your tpl contents but also put the javascript code inside, which will constantly check, using AJAX calls, if an order has been placed.

 

If you use hookactionValidateOrder, then the content is executed on the order validation, but in the same call/session where the order was placed. So this will not help you.

  • Like 1
Link to comment
Share on other sites

 

 

Connect your module only to hookdisplayBackOfficeFooter and here display your tpl contents but also put the javascript code inside, which will constantly check, using AJAX calls, if an order has been placed.

 

Should I in this case used the AJAX calls in the hookactionValidateOrder, to make sure the calls are made if orders has been placed ?

Edited by rayrayrugby (see edit history)
Link to comment
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
×
×
  • Create New...