Automatic Tracking Links

I was looking for a way to add tracking links to the invoice. It is simple enought to just place links in the email invoice, but the links can break because they can get very long like UPS. What I did was to create a simple php module to received a shorten tracking number link from the “completed” invoice. The module determines which shipper tracking number belongs to and automatically links the tracking information for you. If an invalid tracking number is sent, an error message is displayed with a link to your homepage. Here’s how to install this Mod:



Edit your template called mail/orders/invoice.tpl and find this:

[html]

{if $order_info.shipping}

{$lang.shipping_method}: {$order_info.shipping}


{/if}

[/html]

Add these lines of code just below it so it now looks like this:

[html]

{if $order_info.shipping}

{$lang.shipping_method}: {$order_info.shipping}


{/if}

{if $order_info.status == “C”}

{if $order_info.tracking_number|strlen >0}

{$lang.tracking_number}: {$order_info.tracking_number}


{/if}

{/if}

[/html]

Now we need to make a new file called tracking.php and place it where your shopping cart is located. Example: If you cart is located at [url]http://www.shopingcart.com/cart/[/url] then you want tracking in the cart folder. Here is the code:

```php

$tracking=preg_replace("/[^a-z\d]/i", "", $_GET['id']);
$iferr=<<

ERROR! - Tracking Number $tracking Not Found!


http://{$_SERVER['HTTP_HOST']}


HTML;
switch (strlen($tracking)) {

case 11 : header("Location: http://track.dhl-usa.com/TrackByNbr.asp?ShipmentNumber=$tracking"); /* Redirect to DHL */
exit;
break;

case 12 :
case 15 : header("Location: http://www.fedex.com/Tracking?action=track&tracknumbers=$tracking"); /* Redirect to FEDEX */
exit;
break;

case 18 : header("Location: http://wwwapps.ups.com/WebTracking/processRequest?HTMLVersion=5.0&Requester=NES&AgreeToTermsAndConditions=yes&loc=en_US&tracknum=$tracking"); /* Redirect to UPS */
exit;
break;

case 13 :
case 20 :
case 22 : header("Location:http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=$tracking"); /* Redirect to USPS */
exit;
break;

default : echo $iferr;

}
?>

```



Let me know if we need to tweek this MOD.

I implemented this about 2 months ago and it worked great! Now it simply doesn’t work at all…did something change? Do I need to update something? Please let me know if anyone has this working currently. Thanks in advance!!

We tried this mod and get error



Parse error: syntax error, unexpected T_SL in /home/…/public_html/tracking.php on line 3



Has anyone implemented such MOD, please share the solution or suggest the changes we should make in the code.

[quote name=‘smavtron’]We tried this mod and get error



Parse error: syntax error, unexpected T_SL in /home/…/public_html/tracking.php on line 3



Has anyone implemented such MOD, please share the solution or suggest the changes we should make in the code.[/QUOTE]Do you have whitespace between <<


$iferr=<<

[quote name=‘sculptingstudio’]Do you have whitespace between <<


$iferr=<<
[/QUOTE]



This is what I have for the start of the code


```php

$tracking=preg_replace("/[^a-z\d]/i", "", $_GET['id']);
$iferr=<<

ERROR! - Tracking Number $tracking Not Found!


http://{$_SERVER['HTTP_HOST']}


HTML;
switch (strlen($tracking)) {
```

what should be the code, it seems to be correct per your suggestion.

The entire code

```php
$tracking=preg_replace("/[^a-z\d]/i", "", $_GET['id']);
$iferr=<<

ERROR! - Tracking Number $tracking Not Found!


http://{$_SERVER['HTTP_HOST']}


HTML;
switch (strlen($tracking)) {

case 11 : header("Location: http://track.dhl-usa.com/TrackByNbr.asp?ShipmentNumber=$tracking"); /* Redirect to DHL */
exit;
break;

case 12 :
case 15 : header("Location: http://www.fedex.com/Tracking?action=track&tracknumbers=$tracking"); /* Redirect to FEDEX */
exit;
break;

case 18 : header("Location: http://wwwapps.ups.com/WebTracking/processRequest?HTMLVersion=5.0&Requester=NES&AgreeToTermsAndConditions=yes&loc=en_US&tracknum=$tracking"); /* Redirect to UPS */
exit;
break;

case 13 :
case 20 :
case 22 : header("Location:http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=$tracking"); /* Redirect to USPS */
exit;
break;

default : echo $iferr;

}
?>

```

Don’t know but now getting error



Parse error: syntax error, unexpected $end in /home/…/public_html/tracking.php on line 31

[quote name=‘smavtron’]Don’t know but now getting error



Parse error: syntax error, unexpected $end in /home/…/public_html/tracking.php on line 31[/QUOTE]



One may use the following code as an alternative


```php
$tracking=preg_replace(“/[^a-z\d]/i”, “”, $_GET[‘id’]);



switch (strlen($tracking)) {



case 11 : header(“Location: http://track.dhl-usa.com/TrackByNbr.asp?ShipmentNumber=$tracking”); /* Redirect to DHL /

exit;

break;



case 12 :

case 15 : header(“Location: FedEx | System Down”); /
Redirect to FEDEX /

exit;

break;



case 18 : header(“Location: Tracking | UPS - United States”); /
Redirect to UPS /

exit;

break;



case 13 :

case 20 :

case 22 : header(“Location:http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=$tracking”); /
Redirect to USPS */

exit;

break;



default : echo "

ERROR! - Tracking Number $tracking Not Found!


http://{$_SERVER['HTTP_HOST']}

";

}
?> ```

Alexandros

Very good! With Alexandros edit now work fine also on CS 1.3.4 SP3 !



Thanks!

Francesco

That’s what I need. Thank you! :smiley:

I’m still a little confused on where to put the tracking.php file. Does it go in my files on my server or in the template editior admin part of CS-cart?



It is probably a stupid question but I am still fairly new at this.



Regards,



Matthew

Sorry for the confusion.

Thank you, it works like a charm. Just wonder what happen if I have multiple tracking# for the same order?!