Jump to content

add {message} to order_conf.html


Recommended Posts

In the new_order.html template there is a variable called {message}, which displays the message given by the customer.


I want to display this message {message} also in the order_conf.html which is send to the customer.

When I put this variable in the email template it doesn't display the message, just {message}, how can I fix this?


Any help would be apprecitaed!


Thanks in advance


Kind regards



Link to comment
Share on other sites



The order_conf message is set up in the PaymentModule classes' ValidateOrder method, a 500+ row, text-book example of how not to do OOP. Since this method is crucial to PrestaShop's order workflow, overriding it would be a high-risk operation, as an upgrade most probably would break your shop. Editing it would be plausible, but then you'd have to make the same alterations over and over again when you update your shop.


There is, however, a sneaky, somewhat clean way, to force variables into E-mail templates - overriding the Mail class. Try copying the following into a new file Mail.php into your override/classes folder:


class Mail extends MailCore
  public static function Send($id_lang, $template, $subject, $template_vars, $to,
    $to_name = null, $from = null, $from_name = null, $file_attachment = null, $mode_smtp = null, $template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null)
    if($template == 'order_conf' && empty($template_vars['{message}'])){
      $context = Context::getContext();
        $message = Message::getMessageByCartId($context->cart->id);
        $template_vars['{message}'] = empty($message['message']) ? '' : $message['message'];
    return parent::Send($id_lang, $template, $subject, $template_vars, $to,
           $to_name, $from, $from_name, $file_attachment, $mode_smtp, $template_path, $die, $id_shop);

Delete your cache/class_index.php file and try it out. You should be able to use the {message} flag.

On a sidenote, I can think of countless use cases why a hook to add variables to mail templates be a great addition to a new PS version.

Edited by jgullstr (see edit history)
  • Like 4
Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...
  • 11 months later...

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...