Jump to content

[Solved] Add Tracking Number To Email Template?


Recommended Posts

Hello folks,

 

is it possible to automatically add the tracking number set for an order to the email template "in transit"?

 

Instead of the automatically generated link? Just the tracking number?

 

Thanks for any tips and advice on how to do this, would be much appreciated!

 

Happy holidays everyone!

 

Dan

Link to comment
Share on other sites

I also need help with this.

 

I assumed the tracking numbers were viewable in the FO for the customer in their account, but have realized that this is not the case.

 

The "In Transit" e-mail that is sent to the customer upon inputting the tracking number in the BO only provides a link to a website (I use USPS, so the link is http://www.usps.com as that is where the customer will track their package). This link would only be helpful if the tracking number that I input for individual customers is included in the same e-mail. At the very least, the number should be viewable somewhere in the customers' account, but it is not.

 

Please help!!

 

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

You can add the tracking number to the URL only, which works well with some transport companies, but fails on all where the tracking number is not part of the tracking URL.

 

That's why I would like to include a link to the tracking website, and then the tracking number separately.

 

Anyone got an idea?

Link to comment
Share on other sites

you need to edit the admin/tabs/AdminOrders.php file, inside is a function called postProcess. Edit the section that looks like the following code, as you can see I have added 1 line of code with shipping_number

 

$templateVars = array(
   '{followup}' => str_replace('@', $order->shipping_number, $carrier->url),
   '{firstname}' => $customer->firstname,
   '{lastname}' => $customer->lastname,
   '{shipping_number}' => $shipping_number,
   '{id_order}' => (int)($order->id)
);

 

then in your mail template named in_transit.html and in_transit.txt, add {shipping_number} where ever you want the tracking number to appear.

  • Like 7
Link to comment
Share on other sites

  • 3 weeks later...

Hi,

first of all, many thanks for that solution. i have a sililar problem. I use two carriers, one has the tracking number on the url, the other one, does not. the way i see it, with this solution all carriers will behave like this.

Is there a way to specify which "version" i want to use for each carrier, as well as each template to use, the idea is to have

 

carrier #1 -> tracking number in url (use template #1)

carrier #2 -> tracking number to page + "use this tracking number on search box" & tracking number. (use template #2)

  • Like 1
Link to comment
Share on other sites

there are a few ways to accomplish that. you could create multiple templates and then based on the selected carrier, choose the template the use.

if carrier #1 then use template1
else if carrier #2 then use template2

 

or only have a single template, and have the code generate the content that will be displayed, based on the selected carrier

if carrier #1 then
 //assign a variable with the content to be displayed
 //use template 1
else if carrier #2 
 //assign a variable with the content to be displayed
 //use template 1

 

  • Like 1
Link to comment
Share on other sites

thanks for the help :)

however last night i thought that creating all that would be too troublesome and did the method described in this post and will have this method for all carriers. its not too much dificult, it's just a question of copy/pasting the code on the carriers page :)

 

once again thanks for the help.

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...

Hello,

 

Thanks to Bellini for this solution it help me a lot.

 

There is still another small problem, in the order history of the customer, the tracking number do not show up, only the tracking website url.

 

How to do for add the tracking number also the same way like in the email template ?

 

 

 

Notice: My carrier is EMS (China Post) so we cannot use the normal tracking function of prestashop.

Link to comment
Share on other sites

do you enter the tracking number into the system? if so, where do you enter it?

 

Yes, of course I entered the tracking number in the fields "Shipping information".

 

Then the order history of customer is updated only with the tracking website url.

 

Note : If I add the @ in the carrier area then the tracking number is added but it looks not clear for customer :

Click the following link to track the delivery of your order

http://www.ems.com.cn/english.htmlee987654321cn

 

What I want is it looks clear like this :

 

Click the following link to track the delivery of your order

http://www.ems.com.cn/english.html

 

Tracking Number : EE987654321CN

 

Thanks.

Link to comment
Share on other sites

you would need to edit the orderdetailcontroller and the order-detail.tpl, so it does what you want.

 

I've find the code in both files, but I am unable to modify it correctly without crash everything (I am not professional). Can somebody help me with theses codes ?

 

Here is the code for both files :

 

orderdetailcontroller.php :

 

if ($carrier->url AND $order->shipping_number)

self::$smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url));

self::$smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order)));

Module::hookExec('OrderDetail', array('carrier' => $carrier, 'order' => $order));

 

unset($carrier);

unset($addressInvoice);

unset($addressDelivery);

 

 

order-detail.tpl :

 

{if isset($followup)}

<p class="bold">{l s='Click the following link to track the delivery of your order'}</p>

<a href="{$followup|escape:'htmlall':'UTF-8'}">{$followup|escape:'htmlall':'UTF-8'}</a>

{/if}

  • Like 1
Link to comment
Share on other sites

  • 5 months later...
  • 1 month later...
you need to edit the admin/tabs/AdminOrders.php file, inside is a function called postProcess. Edit the section that looks like the following code, as you can see I have added 1 line of code with shipping_number
$templateVars = array( '{followup}' => str_replace('@', $order->shipping_number, $carrier->url), '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{shipping_number}' => $shipping_number, '{id_order}' => (int)($order->id) );

then in your mail template named in_transit.html and in_transit.txt, add {shipping_number} where ever you want the tracking number to appear.

 

The file in 1.5.2 version is located in controllers/admin/AdminOrdersController.php

Link to comment
Share on other sites

Use this instead 1.5.2.:

 

 

'{followup}' => str_replace('@', $order->shipping_number, $carrier->url),

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

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

'{id_order}' => $order->id,

'{shipping_number}' => $order->shipping_number,

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

  • Like 2
Link to comment
Share on other sites

Great,

 

and what about adding all the combinations (not only the first one) in the product description for the new order email template? If it works I'll add it to more places in the backoffice... I'm currently trying to do it because it seems the $itemsTable variable inside /modules/mailalerts/mailalerts.php file only refers to $product['attributes_small'] variable, which seems to have only the first combination. Maybe there is a $product['attributes'] with all the combinations, not only the first one?

 

Another strange thing is that if I modify this $itemsTable variable, for example, in order to change the background of the table, it doesn't change at all. So, I haven't been able to write a var_dump in order to see the $product fields...

 

I'm using Prestashop 1.4.6.2. Thanks in advance!!

Link to comment
Share on other sites

  • 1 month later...

It doesn't work for me.

I use 1.5.2

I added the "declaration" of tracking number field in controllers/admin/AdminOrders.php (as shown by Pressed0024).

I've created a new mail template (based on "in_transit.html/txt"), wrote some sentence containing '{shipping_number}' (without the quotes of courses) and associated it with a brand new status.

When i switch to this status the system send an email but instead of getting the tracking number the text contains {shipping_number} as plain text

 

Any idea ??

Link to comment
Share on other sites

It doesn't work for me.

I use 1.5.2

I added the "declaration" of tracking number field in controllers/admin/AdminOrders.php (as shown by Pressed0024).

I've created a new mail template (based on "in_transit.html/txt"), wrote some sentence containing '{shipping_number}' (without the quotes of courses) and associated it with a brand new status.

When i switch to this status the system send an email but instead of getting the tracking number the text contains {shipping_number} as plain text

 

Any idea ??

 

I have the same problem too. However, i added {shipping_number} to the existing email template and {shipping_number} shows upon the customer email.

I'm using version 1.4.0

 

Any tips?

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Works on PS 1.5.3.1

 

Use this instead 1.5.2.:

 

'{followup}' => str_replace('@', $order->shipping_number, $carrier->url),

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

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

'{id_order}' => $order->id,

'{shipping_number}' => $order->shipping_number,

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

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

  • 4 weeks later...

hello

have verison prestashop 1.5.3.1.

my e-mail templates are working perfectly, but when I wanted to update the shipping tracking number hes generate order number auto. i mean cannot update tracking number any idea ? my engilish bad . thankyou for interesting.

Link to comment
Share on other sites

  • 3 weeks later...

Hi Guys,

thanks for the tips. i managed to get it to work :)

 

so here's what i did...

serched in file "AdminOrdersController.php" for this code:

 

'{followup}' => str_replace('@', $order->shipping_number, $carrier->url),

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

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

'{id_order}' => $order->id,

 

then added this line under it, like instructed:

{shipping_number}' => $order->shipping_number,

 

then on my in_transit.html file

i added this line:

<p>And using the following Tracking Number: <strong>{shipping_number}</strong></p></td>

 

after this one:

<br />You can track your package using the following <a href="{followup}"><strong>Link...</strong></a></p>

 

and now everything is working perfectly :) i'm using version 1.5.3.1

 

TKS :D :D

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

Hi Guys,

thanks for the tips. i managed to get it to work :)

 

so here's what i did...

serched in file "AdminOrdersController.php" for this code:

 

'{followup}' => str_replace('@', $order->shipping_number, $carrier->url),

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

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

'{id_order}' => $order->id,

 

then added this line under it, like instructed:

{shipping_number}' => $order->shipping_number,

 

then on my in_transit.html file

i added this line:

<p>And using the following Tracking Number: <strong>{shipping_number}</strong></p></td>

 

after this one:

<br />You can track your package using the following <a href="{followup}"><strong>Link...</strong></a></p>

 

and now everything is working perfectly :) i'm using version 1.5.3.1

 

TKS :D :D

 

Can you report this bug in forge.prestashop.com so it can be included in the next release update?

  • Like 1
Link to comment
Share on other sites

where is located the file?

 

im tired searching it...(ive google too)

 

 

SOLVED

Its named AdminOrders.php

 

 

 

 

Hi Guys,

thanks for the tips. i managed to get it to work :)

 

so here's what i did...

serched in file "AdminOrdersController.php" for this code:

 

'{followup}' => str_replace('@', $order->shipping_number, $carrier->url),

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

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

'{id_order}' => $order->id,

 

then added this line under it, like instructed:

{shipping_number}' => $order->shipping_number,

 

then on my in_transit.html file

i added this line:

<p>And using the following Tracking Number: <strong>{shipping_number}</strong></p></td>

 

after this one:

<br />You can track your package using the following <a href="{followup}"><strong>Link...</strong></a></p>

 

and now everything is working perfectly :) i'm using version 1.5.3.1

 

TKS :D :D

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

  • 3 weeks later...

Hi Guys,

 

It not works for me. Im using 1.4.6 (dont wanna upgrade to 1.5)

 

After adding thos code as suggested, i cannot see my orders in bo.

 

Received an error :

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /.........../public_html/adminonly/tabs/AdminOrders.php on line 558

 

Please help.

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 2 weeks later...

I used Bellini's solution on 1.4.7 and it works great the tracking number now get's displayed in the "in transit" email, and I also edited the link in the email manually so that you don't get the URL + the tracking number but just the URL.

 

One slight problem though, when a customer logs in, on the order-detail.tpl they can see the tracking number too, how do I get it to appear there, as I've edited order-detail.tpl but the tracking number doesn't appear it's just blank when I try to use {shipping_number} so I assume I need to add some extra call to call the shipping number up or something?

 

Please help as I would like it to appear for both logged in clients and guest tracking, so I guess it will be in OrderDetailController and GuestTrackingController, but I have no idea what to edit/add.

Link to comment
Share on other sites

Nevermind go figure, cant work it out so post up on the forum and then 5 mins after that I make it work.

 

My error was I had {$shipping_number|escape:'htmlall':'UTF-8'} in the order-detail.tpl when in fact I needed

 

{$order->shipping_number|escape:'htmlall':'UTF-8'}

 

I then edited the tracking URL and it all works beautifully now.

Link to comment
Share on other sites

  • 4 weeks later...

there are a few ways to accomplish that. you could create multiple templates and then based on the selected carrier, choose the template the use.

if carrier #1 then use template1
else if carrier #2 then use template2

 

or only have a single template, and have the code generate the content that will be displayed, based on the selected carrier

if carrier #1 then
 //assign a variable with the content to be displayed
 //use template 1
else if carrier #2
 //assign a variable with the content to be displayed
 //use template 1

 

it is work with prestashop 1.5.4.1

thanks a lot

you are nice

and many peopel they look this answer.

 

you need to edit the admin/tabs/AdminOrders.php file, inside is a function called postProcess. Edit the section that looks like the following code, as you can see I have added 1 line of code with shipping_number

 

$templateVars = array(
'{followup}' => str_replace('@', $order->shipping_number, $carrier->url),
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{shipping_number}' => $shipping_number,
'{id_order}' => (int)($order->id)
);

 

then in your mail template named in_transit.html and in_transit.txt, add {shipping_number} where ever you want the tracking number to appear.

Link to comment
Share on other sites

  • 3 weeks later...
you need to edit the admin/tabs/AdminOrders.php file, inside is a function called postProcess. Edit the section that looks like the following code, as you can see I have added 1 line of code with shipping_number
$templateVars = array( '{followup}' => str_replace('@', $order->shipping_number, $carrier->url), '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{shipping_number}' => $shipping_number, '{id_order}' => (int)($order->id) );

then in your mail template named in_transit.html and in_transit.txt, add {shipping_number} where ever you want the tracking number to appear.

 

Dear Friend,

 

I am using Prestashop 1.5.4.1 in that I am unable to find such file. Will be great if you suggest solution on it? Which file should I have to be modified?

 

Thanks

Link to comment
Share on other sites

there are a few ways to accomplish that. you could create multiple templates and then based on the selected carrier, choose the template the use.

if carrier #1 then use template1
else if carrier #2 then use template2

 

or only have a single template, and have the code generate the content that will be displayed, based on the selected carrier

if carrier #1 then
 //assign a variable with the content to be displayed
 //use template 1
else if carrier #2
 //assign a variable with the content to be displayed
 //use template 1

 

Where to mention it? As I have 2 carrier installed. Customer may be select anyone between these two. Even we can ship other carrier than he selected. In such cases what will be solution?

 

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

I apologize for it.

 

I have 2 carrier installed. Customer may be select anyone between these two. But what if we ship using other courier which he not selected. In such cases how to change shipping partner name while entering tracking number?

 

E.g. I have below 2 carriers.

 

FEDEX

 

UPS

 

Customer selected FEDEX.

 

Shipped through UPS then how to select UPS for shipping it? Because system automatically consider courier partner which is selected during checkout by customer.

 

Thanks

  • Like 2
Link to comment
Share on other sites

  • 4 months later...

I already had the code 

'{shipping_number}' => $order->shipping_number,

in my AdminOrdersController.php file, but when I added {shipping_number} in a new template, the number didn't show and I just got {shipping_number}. So this is what I did: 

 

I added the same code... 

'{shipping_number}' => $order->shipping_number,

...in the file classes/order/OrderHistory.php after line

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

So now it looks like this: 

	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,
        '{shipping_number}' => $order->shipping_number,
				'{order_name}' => $order->getUniqReference()
			);

Now it's working in my template. 

  • Like 7
Link to comment
Share on other sites

  • 3 weeks later...

Hello everyone :)

 

i am with PrestaShop 1.5.6.1, i try everything that you tell, but in new version of prestashop it does not work. in email it show up like {shipping_number}

 

Do you have idea of what can i do to work ? I need only shipping number to show, without any URL for tracking.

 

Thanks!

Link to comment
Share on other sites

  • 4 months later...

Hello

I alm using 1.4.11 an 1.4.9 PS

 

I see the shipping_number is OK when you use in_transit.html when you add portion of code.

 

but how can we add the shipping number in other mail like shipped.html or invoice.html.

because the code is only for the case : you clic on submitShippingNumber (/* Update shipping number */)

 

where do i add code in this option :

/* Change order state, add a new entry in order history and send an e-mail to the customer if needed */

 

Thanks a lot

		/* Change order state, add a new entry in order history and send an e-mail to the customer if needed */
		elseif (Tools::isSubmit('submitState') AND ($id_order = (int)(Tools::getValue('id_order'))) AND Validate::isLoadedObject($order = new Order($id_order)))
		{
			if ($this->tabAccess['edit'] === '1')
			{
				$_GET['view'.$this->table] = true;
				if (!$newOrderStatusId = (int)(Tools::getValue('id_order_state')))
					$this->_errors[] = Tools::displayError('Invalid new order status');
				else
				{
					$history = new OrderHistory();
					$history->id_order = (int)$id_order;
					$history->id_employee = (int)($cookie->id_employee);
					$history->changeIdOrderState((int)($newOrderStatusId), (int)($id_order));
					$order = new Order((int)$order->id);
					$carrier = new Carrier((int)($order->id_carrier), (int)($order->id_lang));
					$templateVars = array();
					if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') AND $order->shipping_number)
						$templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url));

					elseif ($history->id_order_state == Configuration::get('PS_OS_CHEQUE'))
						$templateVars = array(
							'{cheque_name}' => (Configuration::get('CHEQUE_NAME') ? Configuration::get('CHEQUE_NAME') : ''),
							'{cheque_address_html}' => (Configuration::get('CHEQUE_ADDRESS') ? nl2br(Configuration::get('CHEQUE_ADDRESS')) : ''));
					elseif ($history->id_order_state == Configuration::get('PS_OS_BANKWIRE'))
						$templateVars = array(
							'{bankwire_owner}' => (Configuration::get('BANK_WIRE_OWNER') ? Configuration::get('BANK_WIRE_OWNER') : ''),
							'{bankwire_details}' => (Configuration::get('BANK_WIRE_DETAILS') ? nl2br(Configuration::get('BANK_WIRE_DETAILS')) : ''),
							'{bankwire_address}' => (Configuration::get('BANK_WIRE_ADDRESS') ? nl2br(Configuration::get('BANK_WIRE_ADDRESS')) : ''));
					if ($history->addWithemail(true, $templateVars))
						Tools::redirectAdmin($currentIndex.'&id_order='.$id_order.'&vieworder'.'&token='.$this->token);
					$this->_errors[] = Tools::displayError('An error occurred while changing the status or was unable to send e-mail to the customer.');
				}
			}
			else
				$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
		}


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

  • 1 year later...

I already had the code 

'{shipping_number}' => $order->shipping_number,

in my AdminOrdersController.php file, but when I added {shipping_number} in a new template, the number didn't show and I just got {shipping_number}. So this is what I did: 

 

I added the same code... 

'{shipping_number}' => $order->shipping_number,

...in the file classes/order/OrderHistory.php after line

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

So now it looks like this: 

	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,
        '{shipping_number}' => $order->shipping_number,
				'{order_name}' => $order->getUniqReference()
			);

Now it's working in my template. 

 

This worked perfectly for me, thank you :)

  • Like 2
Link to comment
Share on other sites

  • 3 months later...
  • 4 months later...
  • 2 weeks later...
  • 1 month later...
  • 3 months later...

As I have seen many threads about this, just for info, in 1.6.1.14 you don't need to edit any of the core files. Simply add {shipping_number} in your email template, and it will be replaced by the tracking number.

Hi,

 

I am using 1.6.1.16 and it is still showing the text {shipping_number} in the email???

Link to comment
Share on other sites

Hi,

 

I am using 1.6.1.16 and it is still showing the text {shipping_number} in the email???

1) which email did you change?  which email are you expecting the tracking number to appear in?

2) when did you add a tracking number to the order?

3) are you expecting the tracking number to appear in the carrier tracking URL?

Link to comment
Share on other sites

1) which email did you change?  which email are you expecting the tracking number to appear in?

2) when did you add a tracking number to the order?

3) are you expecting the tracking number to appear in the carrier tracking URL?

 

Hi,

 

I add the {shipping_number} in the in_transit email, as a seperate line,

 

this email will be sent when I add the tracking number in the back office, after the shipped status....

 

it used to work fine, but now it just showing the text...

 

i am not expecting this in the tracking URL...

Link to comment
Share on other sites

  • 1 year later...

I already had the code 

'{shipping_number}' => $order->shipping_number,

in my AdminOrdersController.php file, but when I added {shipping_number} in a new template, the number didn't show and I just got {shipping_number}. So this is what I did: 

 

I added the same code... 

'{shipping_number}' => $order->shipping_number,

...in the file classes/order/OrderHistory.php after line

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

So now it looks like this: 

	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,
        '{shipping_number}' => $order->shipping_number,
				'{order_name}' => $order->getUniqReference()
			);

Now it's working in my template. 

 

Thanks it worked!!!!! Version 1.6.1.12

Link to comment
Share on other sites

I found a solutin.

 

My Prestashop is 1.6.16

 

I have changed the lines from 409 to 413

$templateVars = array('{shipping_number}' => $order->shipping_number);
if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $order->shipping_number)
{
$templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url),
'{shipping_number}' => $order->shipping_number);

and i have edited the "in transit" email template in the BO.

 

I have added {shipping_number} and other details like email template "Shipped"

 

and then unclicked shipped email template from status to not send email to recevier because when you add tracking number the received get all details about order status and tracking nuber and carriers page details.

 

It works perfectly.

 

Best Regards

.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...