Jump to content

[SOLVED] Different email templates for different user groups


Recommended Posts

Hi,

I'm trying to make my prestatshop to send a different email template, for example no shipping prices included, for a special user group. Because I will need to manage this customer's shipping cost manually and send a another shipping cost email.

Please advise if this is possible or I need a custom module.

Regards

Link to comment
Share on other sites

  • 4 weeks later...

My situation is a little bit different from "paranoiac" mentioned in first message.
I have two groups and i need to send different Design emails (order_conf) after order complete.

Maybe in PaymentModule.php we can change below "'// Send an e-mail to customer"" , then we can have two templates for different groups?

Link to comment
Share on other sites

Yes, that would work. Create two separate mail templates order_conf1 and order_conf2 and add the following to classes/PaymentModule.php after line 83 (in PrestaShop v1.3.2):

$customer = new Customer(intval($cart->id_customer));



then change line 376 from:

Mail::Send(intval($order->id_lang), 'order_conf', 'Order confirmation', $data, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment);



to:

Mail::Send(intval($order->id_lang), 'order_conf' . $customer->id_default_group, 'Order confirmation', $data, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment);

Link to comment
Share on other sites

No, you can't use Smarty code in mail templates. The only thing I can think of is to create a {shipping} variable that contains the shipping information for one customer group and is a blank variable for the other customer group.


Would you please give me an example? like which file(s) I need to edit etc..
Thanks in advance, rocky.
Link to comment
Share on other sites

Like above, add the following to classes/PaymentModule.php after line 83 (in PrestaShop v1.3.2):

$customer = new Customer(intval($cart->id_customer));



then add the following before the $data array on line 324:

$shipping = '                    
 
Shipping
' . Tools::displayPrice($order->total_shipping, $currency, false, false) . '
';
if (intval($customer->id_default_group) == 2)
  $shipping = '';



then in the $data array, change:

'{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false, false),



to:

'{shipping}'  => $shipping,



Then you can use {shipping} in order_conf.html and it will display the shipping total unless the customer is in group 2.

Link to comment
Share on other sites

  • 2 weeks later...

Sorry for late response, I updated this thread to solved.
Even though there is a slight html modification to make it perfect due to my personal preference. :)


To rocky,
Thank you very much once again.

In addition, the {total_paid} , the biggest sum, still use the hidden {shipping} (if it is >= 1) to calculate.
I thought we have put an empty string to it when the customer group is 2.
Please advise.

Link to comment
Share on other sites

  • 2 months later...
  • 9 years later...
  • 1 year later...

Prestashop 1.7.7

To use different E-Mail Templates by Group, Carrier, User, or what ever:
Use the Hook sendMailAlterTemplateVars in your Module... 
Dont forget to create the templates in /themes/xxxx/mails/xx/order_confsomethingother.html

$this->registerHook('actionEmailSendBefore');

 

public function hookActionEmailSendBefore(&$params) {
		
 
	if($params["template"] == "order_conf") { # or bankwire or ,.....
		
		

		$reference = $params['templateVars']['{order_name}'];
		$sql = 'SELECT * FROM '._DB_PREFIX_.'orders WHERE reference = "'.$reference.'" Limit 1 ';
		$orderRow = Db::getInstance()->executeS($sql);
		
	   
		if (!empty($orderRow)) { 
		
			$id_order = reset($orderRow)['id_order'];
			$order = new Order ($id_order);
			
			if($order->id_carrier == "36") {
				$params['template'] = "order_confsomethingother";
			}
			
			/*
			For User Groups you can use something like this:
			$customer = new Customer ($order->id_customer);
			if($customer->id_group == "36") {
				$params['template'] = "order_confsomethingother2222";
			} 
			*/
		}
		
		# do something more...
		if (is_array($params['bcc']))
		{
			$params['bcc'][] = "[email protected]";
		}			
		else
		{
			$params['bcc'] = ["[email protected]"];
		}
	}
}

 

If you want to add variables, use: sendMailAlterTemplateVars

Edited by heyho (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...