Jump to content

[SOLVED] Email variables


Recommended Posts

Is there any variable for customer email ?

I mean when i create some email templates (you know like bankwire,shipped,contact form etc) then i can put some variables like {id_order} and customer will get his correct order number

BUT what about customer email ?

If i would like to create mail template with something like "your email address {email}"

 

is there any variable for that ?

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

which php file is responsible for variables used in "system" emails like "shipping, bankwire" etc ?

 

inside these templates there are variables like {id_order} which works fine if i put them in new email template but i dont see anywhere variable which would allow me to "print" customers email used for order

 

there is variable {email} used in contact form template but this doesnt work because this is email which visitors put in contact form email field - not email that client used to generate order

Link to comment
Share on other sites

i want to create new email template which will be one of statuses which i can send to client

 

inside this email i would like to put variables like order number, clients email

for order numer there is variable {id_order} and it works, but what about client's email ?

Link to comment
Share on other sites

I understand you, but I need to know wich php file send the email because you need add email variable to these file, if I don't know wich the file I can't help you because all variables are generated from these file, that's why I have asked exactly if this email is sent from a module or where is generated.

Link to comment
Share on other sites

Ok try this, in the file: classes/order/OrderHistory.php

 

Locate lines below:

			$data = array(
				'{lastname}' => $result['lastname'],
				'{firstname}' => $result['firstname'],
				'{id_order}' => (int)$this->id_order,
				'{order_name}' => $order->getUniqReference()
			);

Now replace for this below:

			$data = array(
				'{email}' => $result['email'],
				'{lastname}' => $result['lastname'],
				'{firstname}' => $result['firstname'],
				'{id_order}' => (int)$this->id_order,
				'{order_name}' => $order->getUniqReference()
			);

In your email template use {email} for the customer email, i have not tested, please test in let me know hwat happen.

 

regards.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

i wonder if its possible to do the same with order date and shipping date ?

 

I mean get variable which would print date when order was made and other variable which would print date of shipping

 

This need more changes.

In the file: classes/order/OrderHistory.php

 

Locate lines below:

		$result = Db::getInstance()->getRow('
			SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, os.`id_order_state`
			FROM `'._DB_PREFIX_.'order_history` oh
				LEFT JOIN `'._DB_PREFIX_.'orders` o ON oh.`id_order` = o.`id_order`
				LEFT JOIN `'._DB_PREFIX_.'customer` c ON o.`id_customer` = c.`id_customer`
				LEFT JOIN `'._DB_PREFIX_.'order_state` os ON oh.`id_order_state` = os.`id_order_state`
				LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = o.`id_lang`)
			WHERE oh.`id_order_history` = '.(int)$this->id.' AND os.`send_email` = 1');
		if (isset($result['template']) && Validate::isEmail($result['email']))
		{
			ShopUrl::cacheMainDomainForShop($order->id_shop);
			
			$topic = $result['osname'];
			$data = array(
				'{lastname}' => $result['lastname'],
				'{firstname}' => $result['firstname'],
				'{id_order}' => (int)$this->id_order,
				'{order_name}' => $order->getUniqReference()
			);

Now replace for this below:

		$result = Db::getInstance()->getRow('
			SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, os.`id_order_state`, oh.`date_add`, oh.`delivery_date`
			FROM `'._DB_PREFIX_.'order_history` oh
				LEFT JOIN `'._DB_PREFIX_.'orders` o ON oh.`id_order` = o.`id_order`
				LEFT JOIN `'._DB_PREFIX_.'customer` c ON o.`id_customer` = c.`id_customer`
				LEFT JOIN `'._DB_PREFIX_.'order_state` os ON oh.`id_order_state` = os.`id_order_state`
				LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = o.`id_lang`)
			WHERE oh.`id_order_history` = '.(int)$this->id.' AND os.`send_email` = 1');
		if (isset($result['template']) && Validate::isEmail($result['email']))
		{
			ShopUrl::cacheMainDomainForShop($order->id_shop);
			
			$topic = $result['osname'];
			$data = array(
				'{email}' => $result['email'],
				'{lastname}' => $result['lastname'],
				'{firstname}' => $result['firstname'],
				'{id_order}' => (int)$this->id_order,
				'{order_name}' => $order->getUniqReference(),
				'{order_date_add}' => $result['date_add'],
				'{order_delivery_date}' => $result['delivery_date']
			);

Now in your email template use:

{email} for the customer email

{order_date_add} for date add

{order_delivery_date} for delivery date (if is not delivered yet, this should be empty)

 

 

 

regards.

Link to comment
Share on other sites

many many thanks

 

 

 

 

 

 

but... i forgot about most important thing - variable for product name (i mean product which was ordered)

 

this is the last thing i need :)

 

 

Use this:

		$result = Db::getInstance()->getRow('
			SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, os.`id_order_state`, oh.`date_add`, oh.`delivery_date`
			FROM `'._DB_PREFIX_.'order_history` oh
				LEFT JOIN `'._DB_PREFIX_.'orders` o ON oh.`id_order` = o.`id_order`
				LEFT JOIN `'._DB_PREFIX_.'customer` c ON o.`id_customer` = c.`id_customer`
				LEFT JOIN `'._DB_PREFIX_.'order_state` os ON oh.`id_order_state` = os.`id_order_state`
				LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = o.`id_lang`)
			WHERE oh.`id_order_history` = '.(int)$this->id.' AND os.`send_email` = 1');
		if (isset($result['template']) && Validate::isEmail($result['email']))
		{
			ShopUrl::cacheMainDomainForShop($order->id_shop);
			
			$topic = $result['osname'];
			$data = array(
				'{email}' => $result['email'],
				'{lastname}' => $result['lastname'],
				'{firstname}' => $result['firstname'],
				'{id_order}' => (int)$this->id_order,
				'{order_name}' => $order->getUniqReference(),
				'{order_products}' => Db::getInstance()->getValue('SELECT GROUP_CONCAT(" ", `product_name`) AS product_name FROM `'._DB_PREFIX_.'order_detail` WHERE `id_order` = '.(int)$this->id_order),
				'{order_date_add}' => $result['date_add'],
				'{order_delivery_date}' => $result['delivery_date']
			);

And call products name with {order_products}

Link to comment
Share on other sites

  • 4 weeks later...

Hi, I would like to integrate Customer ID into one of the email templates. It is the Order Confirmation email, that starts with:

 

Hi {firstname} {lastname}

Thank you for shopping with {shop_name}!

 

I have tried this:

 

in the file: classes/order/OrderHistory.php

 

Locate lines below:

            $data = array(
                '{lastname}' => $result['lastname'],
                '{firstname}' => $result['firstname'],
                '{id_order}' => (int)$this->id_order,
                '{order_name}' => $order->getUniqReference()
            );

Now replace for this below:

            $data = array(
                '{id_customer}' => $result['id_customer'],
                '{lastname}' => $result['lastname'],
                '{firstname}' => $result['firstname'],
                '{id_order}' => (int)$this->id_order,
                '{order_name}' => $order->getUniqReference()
            );

 

 

But it did not work. Would anyone be able to help me with it. Thank you so much.

Link to comment
Share on other sites

 

Hi, I would like to integrate Customer ID into one of the email templates. It is the Order Confirmation email, that starts with:

 

Hi {firstname} {lastname}

 

Thank you for shopping with {shop_name}!

 

I have tried this:

 

in the file: classes/order/OrderHistory.php

 

Locate lines below:

            $data = array(

                '{lastname}' => $result['lastname'],

                '{firstname}' => $result['firstname'],

                '{id_order}' => (int)$this->id_order,

                '{order_name}' => $order->getUniqReference()

            );

Now replace for this below:

            $data = array(

                '{id_customer}' => $result['id_customer'],

                '{lastname}' => $result['lastname'],

                '{firstname}' => $result['firstname'],

                '{id_order}' => (int)$this->id_order,

                '{order_name}' => $order->getUniqReference()

            );

 

 

But it did not work. Would anyone be able to help me with it. Thank you so much.

 

That's it because you need add first these parameter in the SQL, eg:

SELECT osl.`template`, *** *** *** *** *** *** ***, c.`id_customer`

 

Regards.

Link to comment
Share on other sites

I think that is too advanced for me. Is it a matter of replacing some code or shall I hire somebody to do this for me? Thank you COTOKO for a quick reply

I mean to the SQL line that exists little earlier, like this:

SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, os.`id_order_state`

 

Just need add the customer id in the end, like this:

SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, os.`id_order_state`, c.`id_customer`

 

 

I hope this help.

Link to comment
Share on other sites

Hi, unfortunately it is still not working. I am defining {id_customer} in the email template but it is still not coming up correctly. :(

 

 

 

SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, os.`id_order_state`, c.`id_customer`
FROM `'._DB_PREFIX_.'order_history` oh
LEFT JOIN `'._DB_PREFIX_.'orders` o ON oh.`id_order` = o.`id_order`
LEFT JOIN `'._DB_PREFIX_.'customer` c ON o.`id_customer` = c.`id_customer`
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON oh.`id_order_state` = os.`id_order_state`
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = o.`id_lang`)
WHERE oh.`id_order_history` = '.(int)$this->id.' AND os.`send_email` = 1');
if (isset($result['template']) && Validate::isEmail($result['email']))
{
ShopUrl::cacheMainDomainForShop($order->id_shop);
 
$topic = $result['osname'];
$data = array(
'{id_customer}' => $result['id_customer'],
'{lastname}' => $result['lastname'],
'{firstname}' => $result['firstname'],
'{id_order}' => (int)$this->id_order,
'{order_name}' => $order->getUniqReference()
);
  • Like 1
Link to comment
Share on other sites

Hi, yes I have double checked. It still din't work though. Any ideas? I need a unique customer identifier in the email as there can be more customers with the same name so I though {id_customer} would be ideal.

 

Any more thoughts what could be wrong here?

Thank you

Link to comment
Share on other sites

Assuming it is PS v1.5, there is no need to change OrderHistory class.  Just edit/override the PaymentModule class and add the id_customer as

 

$data = array(
'{id_customer}' => $this->context->customer->id,

'{firstname}' => $this->context->customer->firstname,
'{lastname}' => $this->context->customer->lastname,
'{email}' => $this->context->customer->email,
...

}

Link to comment
Share on other sites

  • 1 month later...

 

Assuming it is PS v1.5, there is no need to change OrderHistory class.  Just edit/override the PaymentModule class and add the id_customer as

 

$data = array(

'{id_customer}' => $this->context->customer->id,

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

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

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

...

}

 

This not work's for me on Presta 1.5.6.1 :(

Also not working:

'{id_customer}' => $this->context->customer->id_customer,

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

 

Hi, unfortunately it is still not working. I am defining {id_customer} in the email template but it is still not coming up correctly. :(

 

 

 

SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, os.`id_order_state`, c.`id_customer`
FROM `'._DB_PREFIX_.'order_history` oh
LEFT JOIN `'._DB_PREFIX_.'orders` o ON oh.`id_order` = o.`id_order`
LEFT JOIN `'._DB_PREFIX_.'customer` c ON o.`id_customer` = c.`id_customer`
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON oh.`id_order_state` = os.`id_order_state`
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = o.`id_lang`)
WHERE oh.`id_order_history` = '.(int)$this->id.' AND os.`send_email` = 1');
if (isset($result['template']) && Validate::isEmail($result['email']))
{
ShopUrl::cacheMainDomainForShop($order->id_shop);
 
$topic = $result['osname'];
$data = array(
'{id_customer}' => $result['id_customer'],
'{lastname}' => $result['lastname'],
'{firstname}' => $result['firstname'],
'{id_order}' => (int)$this->id_order,
'{order_name}' => $order->getUniqReference()
);

 

This work's on my Presta 1.5.6.1 !  THX

Link to comment
Share on other sites

  • 3 months later...

I want to do the same thing with the "product_quantity_in_stock" of the table "order_detail" but i block with my SQL request...  if someone can help me ? I guess I have to make another "LEFT JOIN" with the table "order_detail" but i failed each time...

 

$result = Db::getInstance()->getRow('
SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, od.`product_quantity_in_stock`
FROM `'._DB_PREFIX_.'order_history` oh
LEFT JOIN `'._DB_PREFIX_.'orders` o ON oh.`id_order` = o.`id_order`
LEFT JOIN `'._DB_PREFIX_.'customer` c ON o.`id_customer` = c.`id_customer`
???????????????????????????????????
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON oh.`id_order_state` = os.`id_order_state`
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = o.`id_lang`)
WHERE oh.`id_order_history` = '.(int)$this->id.' AND os.`send_email` = 1');
if (isset($result['template']) && Validate::isEmail($result['email']))
{
$topic = $result['osname'];
$data = array(
'{lastname}' => $result['lastname'],
'{firstname}' => $result['firstname'],
'{id_order}' => (int)$this->id_order,
'{order_name}' => $order->getUniqReference(),
                '{order_quantity}' => Db::getInstance()->getValue('SELECT GROUP_CONCAT(" ", `product_quantity_in_stock`) AS product_quantity FROM `'._DB_PREFIX_.'order_detail` WHERE `id_order` = '.(int)$this->id_order),
                
);

 

Thanks !

Link to comment
Share on other sites

  • 1 year later...

Hello all.

 

I know this topic is a little old. But taking advantage of the topic. I would like to know how I could add in the email template the customer and I receive (notification) before the name of the product, it's picture? 

 

Thank you in advance

Link to comment
Share on other sites

  • 2 years later...

Hello,

I'm using Prestashop 1.6.1.13 and cant get his to work. I want to display price for shiping excl. tax.

 

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

Is not working, any idea what i should do?

Link to comment
Share on other sites

×
×
  • Create New...