Jump to content

How to create my own custom email when order confirm is processed?


mobo247

Recommended Posts

Hi dev forum,

 

I am a new developer to php and prestashop and I am using prestashop v1.6.

 

I want to create my own custom email to send to the customer and the merchant owner.  I am having some trouble locating the module or php class or method that send the email (for example the Order confirmation email). I know in the admin console in Localization->Translations->Translations (under mailalerts new_order option) you can edit the HTML or text version of the email.   It has special attributes like {shop_url}, {payment}, {order_name} and etc.  I would like to add my own custom attribute {myownattr} to the list and be visible to the html and create my own custom email.  I want to be able to add a vendor name, specific URL links, voucher code, voucher barcode, or custom generated QR code to the display on the email.   How and where can I do that?  Maybe some where in the send mail module (Mail.php)?  

 

Thank you in advance for any help!

-Steve.

 

 

Link to comment
Share on other sites

Hi Steve,

 

It is the PaymentModule class that sends the order confirmation email to the customer.  It has a function named validateOrder that executes this.

 

You can edit the PaymentModule class or create an override and add the additional email template attributes that you require.

 

As for the new order notification that goes to the merchant, you would need to make similar changes to the mailalert module.

  • Like 1
Link to comment
Share on other sites

Thanks Bellini13 for you quick response!  I found it in the  mailalerts.php in the function hookActionValidateOrder($params).  I hope by adding my custom attributes here in the  $template_vars array, they will be visible to the html replacement variables.  Many thanks.

 

Hope this topic will help other prestashop newbies too.

-Steve.

 

mailalerts.php:

-----------------------

public function hookActionValidateOrder($params)
{  
......

// Filling-in vars for email

$template_vars = array(
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{email}' => $customer->email,
Link to comment
Share on other sites

It didn't work.  I added my custom attribute in the the $template_vars array in mailalerts.php but it didn't work.  The html email sent couldn't find the my custom attribute to print 'hellothere'.  What am I missing here?  Again this is the "Order Confirmation" email to the customer.

Any hint will will be great.

 

-Steve.

 

mailalerts.php:

-------------------

$template_vars = array(

'{firstname}' => $customer->firstname,

'{lastname}' => $customer->lastname,

'{email}' => $customer->email,

'{customattr}' => 'hellothere', 

.......

 

~/www/themes/default-bootstrap/mails/en/order_conf.html

---------------------------------------------------------------------------------------------------

<td> <span> {customattr}</span></td>
Link to comment
Share on other sites

you added the attribute to the wrong template file.  order_conf.html is not used by mailalerts, it is used by PaymentModule to send the email to the customer

 

For the notification email that goes to the merchant, look in the mailalerts module folder for the correct mail template to use.

  • Like 1
Link to comment
Share on other sites

  • 2 years 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...