title: Prestashop 1.6 - Using emails hooks
body: <p>I am currently building a shop using Prestashop 1.6.1.5.</p>
  
  <p>As emails I must send are numerous, I would like to manage my email skeletton in a single place.<br>
  I think that the easier way would be to manage emails into smarty files and to [extend my layout][1].</p>
  
  <p>Does anyone now a transparent and global way to manage email layouts?</p>
  
  <p>Thanks,</p>
  
  <p>Ben.</p>
  
  <h1>[EDIT]</h1>
  
  <p>Diving into MailCore class, I saw that email templates can be manipulated before send using three hooks (simplified and commented) : </p>
  
  <pre class="lang-php prettyprint-override"><code>// Init empty templates strings.
  $template_html = '';
  $template_txt = '';
  
  // Manipulate strings before importing templates.
  Hook::exec('actionEmailAddBeforeContent', array(
      'template_html' =&gt; &amp;$template_html,
      'template_txt' =&gt; &amp;$template_txt,
      // ...
  ), null, true);
  
  // Import templates.
  $template_html .= Tools::file_get_contents(/* ... */);
  $template_txt .= strip_tags(html_entity_decode(Tools::file_get_contents(/* ... */), null, 'utf-8'));
  
  // Manipulate strings after importing templates.
  Hook::exec('actionEmailAddAfterContent', array(
      'template_html' =&gt; &amp;$template_html,
      'template_txt' =&gt; &amp;$template_txt,
      // ...
  ), null, true);
  
  // Some MailCore stuff.
  
  // Inject custom vars before generate email content
  $extra_template_vars = array();
  Hook::exec('actionGetExtraMailTemplateVars', array(
      'template_vars' =&gt; $template_vars,
      'extra_template_vars' =&gt; &amp;$extra_template_vars,
      // ...
  ), null, true);
  $template_vars = array_merge($template_vars, $extra_template_vars);
  
  // Generate and send email
  </code></pre>
  
  <p>So it seems to me that using these hooks is the good way to manage my email layout, but I don't get how it's work to define the function called by hooks.</p>
  
  <p>To make it global, I tried to override MailCore (into <strong>/override/classes/Mail.php</strong>) :</p>
  
  <pre class="lang-php prettyprint-override"><code>class Mail extends MailCore {
  
      public function __construct($id = null, $id_lang = null, $id_shop = null) {
          parent::__construct($id, $id_lang, $id_shop);
          PrestaShopLogger::addLog('MailCore overrided!');
      }
  
      // Prepend a header to template.
      public function hookActionEmailAddBeforeContent($params) {
          PrestaShopLogger::addLog('hookActionEmailAddBeforeContent called!');
          $params['template_html'] .= '&lt;h1&gt;{myheader}&lt;/h1&gt;';
      }
  
      // Append a footer to template.
      public function hookActionEmailAddAfterContent($params) {
          PrestaShopLogger::addLog('hookActionEmailAddAfterContent called!');
          $params['template_html'] .= '&lt;h1&gt;{myfooter}&lt;/h1&gt;';
      }
  
      // Add my custom vars.
      public function hookActionGetExtraMailTemplateVars($params) {
          PrestaShopLogger::addLog('hookActionGetExtraMailTemplateVars called!');
          $params['extra_template_vars']['myheader'] = 'This is a header';
          $params['extra_template_vars']['myfooter'] = 'This is a footer';
      }
  
  }
  </code></pre>
  
  <p>After clearing Prestashop cache, class override works (log from constructor) but none of my hooks is called.<br>
  I also tried to register hooks using <code>$this-&gt;registerHook('...');</code> into my class constructoe, but without any effect.</p>
  
  <p>If anyone could help, It would be very great.</p>
  
  <p>Thanks,</p>
  
  <p>Ben.</p>