Jump to content

Orders - New Status With Email


Recommended Posts

Hi everybody,

 

I have the following problem :

I create a new order status, with an associate e-mail that I have created before. When I change my order status to my new one, the email is well sent but the variables in the email are not interpreted. In fact, I don't know how to associate some variables into my email...

 

Someone knows how can I do this (excepting by developping it :rolleyes: ) ?

 

Thanks

Edited by anatolesaby (see edit history)
Link to comment
Share on other sites

Hi,

I assume you also created a custom function to send out emails. Here is the send function, as it appears in the Mail class

 

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)

 

As you can see, there is a "template_vars" variable. That is supposed to be an array with your template variables, setup like this:

array(
'{name}' => $name,
'{address}' => $this->address
);

 

Of course, those php variables are just examples. The important part is the array key, which must be a string with brackets

Link to comment
Share on other sites

  • 1 year later...

Sorry for digging this thread up, but i have a similar problem.

 

I don´t use an own send function but want to use the order status mail function.

$this->module->validateOrder((int)$cart->id, Configuration::get('PS_OS_PAYMENTMODULE'), $total, $this->module->displayName, $message, $mailVars, (int)$currency->id, false, $customer->secure_key);

Only the Variables {lastname} {firstname} {id_order} {order_name} and {total_paid} work and of course fixed varibales like

'{email}' => 'testtesttest

 

But not Variables like

'{invoice_firstname}' => $invoice->firstname,

'{invoice_city}' => $this->context->address_invoice->city, or

'{invoice_postal_code}' => $cart->address_invoice->postal_code,

 

Has anyone an idea?

Link to comment
Share on other sites

Thank you for your patience.

 

I solved it

 

Here ist the full code for the file \modules\cheque\controllers\front\validation.php

class ChequeValidationModuleFrontController extends ModuleFrontController
{
	public function postProcess()
	{
		$cart = $this->context->cart;
		
		$invoice = new Address((int)$cart->id_address_invoice);
		$customer = new Customer($cart->id_customer);
				
		if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active)
			Tools::redirect('index.php?controller=order&step=1');

		// Check that this payment option is still available in case the customer changed his address just before the end of the checkout process
		$authorized = false;
		foreach (Module::getPaymentModules() as $module)
			if ($module['name'] == 'cheque')
			{
				$authorized = true;
				break;
			}

		if (!$authorized)
			die($this->module->l('This payment method is not available.', 'validation'));

		 

		if (!Validate::isLoadedObject($customer))
			Tools::redirect('index.php?controller=order&step=1');

		$currency = $this->context->currency;
		$total = (float)$cart->getOrderTotal(true, Cart::BOTH);

		$mailVars =	array(
			'{cheque_name}' => Configuration::get('CHEQUE_NAME'),
			'{cheque_address}' => Configuration::get('CHEQUE_ADDRESS'),
			'{cheque_address_html}' => str_replace("\n", '<br />', Configuration::get('CHEQUE_ADDRESS')),
			'{email}' => $this->context->customer->email,
			'{date}' => Tools::displayDate(date('Y-m-d H:i:s'),null , 0),			
			'{invoice_company}' => $invoice->company,
			'{invoice_firstname}' => $invoice->firstname,
			'{invoice_lastname}' => $invoice->lastname,
			'{invoice_address2}' => $invoice->address1,
			'{invoice_address1}' => $invoice->address2,
			'{invoice_city}' => $invoice->city,
			'{invoice_postal_code}' => $invoice->postal_code,
			'{invoice_country}' => $invoice->country
			
			);

		$this->module->validateOrder((int)$cart->id, Configuration::get('PS_OS_CHEQUE'), $total, $this->module->displayName, NULL, $mailVars, (int)$currency->id, false, $customer->secure_key);
		Tools::redirect('index.php?controller=order-confirmation&id_cart='.(int)$cart->id.'&id_module='.(int)$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key);
	}
}

Important is the line:

$invoice = new Address((int)$cart->id_address_invoice);

Can I do it this way, or is there any security issue?

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