Jump to content

how to troubleshoot a actionhook not being called / not working ? PS 1.6.x

Recommended Posts

Hi All,


I have a (very simple) module that hooks into actionGetExtraMailTemplateVars

I'd like to be able to get some additional template_vars available dependent on template and other context available.


So i created a module, it installs fine, the hook is registered (i can find it in the modules / hooks overview on the action hook: hookActionGetExtraMailTemplateVars)

however it seems to be either not called, or not working as expected. (I added a log statement to the method, and i would expect to see that log statement in the logs)


this is the code (the entire module.php file):


if (!defined('_PS_VERSION_')) {
class ExtraEmailFields extends Module
    public function __construct()
        $this->name = 'extraemailfields';
        $this->version = '1.0.0';
        $this->author = 'Henrik Ohm Eriksen';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = array('min' => '1.5', 'max' => _PS_VERSION_);
        $this->bootstrap = true;
	        $this->displayName = $this->l('ExtraEmailFields');
        $this->description = $this->l('Extra Email Fields. Adds additional email merge fields based on available content in template and template selected. Developed by Henrik Ohm Eriksen.');
	        $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
    public function install()
        if (parent::install() == false)
            return false;
        return true;
    public function uninstall()
        if (parent::uninstall() == false)
            return false;
        //Apparantly not neeeded $this->unregisterHook('hookActionGetExtraMailTemplateVars');    
        return true;
	    //Actual Hook Code
    public function hookActionGetExtraMailTemplateVars($params)
        PrestaShopLogger::addLog('my_hook', 1);
        //Extract Context
        $template = $params['template'];
        $template_vars = $params['template_vars'];
        $extra_template_vars = $params['extra_template_vars'];
	        $params['extra_template_vars']['{myVar1}'] = 'FOO_VAR1';
        $params['extra_template_vars']['{myVar2}'] = 'FOO_VAR2';
        $params['extra_template_vars']['{myVar3}'] = 'FOO_VAR3';
	        /*more code here temporarily commented out while troubleshooting*/


Anybody have an idea what I did wrong ?




Share this post

Link to post
Share on other sites

In PS v1.6, the hook is executed within the Mail class, and it should get executed every time a Mail is sent (there are no conditions).

            Hook::exec('actionGetExtraMailTemplateVars', array(
                'template' => $template,
                'template_vars' => $template_vars,
                'extra_template_vars' => &$extra_template_vars,
                'id_lang' => (int)$id_lang
            ), null, true);

This statement in your module is wrong however. 


The name of the hook is actionGetExtraMailTemplateVars, so you should register it like this...


After changing your code, use the module reset option in the back office which will uninstall and install your module again.

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
  • Create New...

Important Information

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