Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Automatic Tracking Links Rate Topic   - - - - -

 

Posted 04 October 2006 - 04:52 AM #1

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:

{if $order_info.shipping}
<b>{$lang.shipping_method}:</b>  {$order_info.shipping}<br />
{/if}

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

{if $order_info.shipping}
<b>{$lang.shipping_method}:</b>  {$order_info.shipping}<br />
{/if}
{if $order_info.status == "C"}
{if $order_info.tracking_number|strlen >0}
<b>{$lang.tracking_number}:</b> <a href="{$http_location}/tracking.php?id={$order_info.tracking_number}">{$order_info.tracking_number}</a><br />
{/if}
{/if}

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 http://www.shopingcart.com/cart/ then you want tracking in the cart folder. Here is the code:

<?php
$tracking=preg_replace("/[^a-z\d]/i", "", $_GET['id']);
$iferr=<<<HTML
<p style="text-align:center;color:red;">ERROR! - Tracking Number $tracking Not Found!</p>
<p style="text-align:center;"><a href="http://{$_SERVER['HTTP_HOST']}">http://{$_SERVER['HTTP_HOST']}</a></p>
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.

Larry
SculptingStudio.com
DigitalOcean VM

Ubuntu 14.04

Nginx


 
  • pako
  • Junior Member
  • Members
  • Join Date: 04-Oct 06
  • 21 posts

Posted 29 March 2007 - 10:13 PM #2

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!!

 
  • coder
  • Senior Member
  • Members
  • Join Date: 19-Jun 07
  • 411 posts

Posted 01 July 2007 - 09:39 PM #3

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.

 

Posted 02 July 2007 - 08:35 PM #4

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.

Do you have whitespace between <<<HTML ? Make the line look like this:

$iferr=<<<HTML

Larry
SculptingStudio.com
DigitalOcean VM

Ubuntu 14.04

Nginx


 
  • coder
  • Senior Member
  • Members
  • Join Date: 19-Jun 07
  • 411 posts

Posted 02 July 2007 - 08:47 PM #5

Do you have whitespace between <<<HTML ? Make the line look like this:

$iferr=<<<HTML


This is what I have for the start of the code

<?php 
$tracking=preg_replace("/[^a-z\d]/i", "", $_GET['id']); 
$iferr=<<<HTML 
<p style="text-align:center;color:red;">ERROR! - Tracking Number $tracking Not Found!</p> 
<p style="text-align:center;"><a href="http://{$_SERVER['HTTP_HOST']}">http://{$_SERVER['HTTP_HOST']}</a></p> 
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=<<<HTML 
<p style="text-align:center;color:red;">ERROR! - Tracking Number $tracking Not Found!</p> 
<p style="text-align:center;"><a href="http://{$_SERVER['HTTP_HOST']}">http://{$_SERVER['HTTP_HOST']}</a></p> 
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; 

} 
?> 


 
  • coder
  • Senior Member
  • Members
  • Join Date: 19-Jun 07
  • 411 posts

Posted 02 July 2007 - 11:46 PM #6

Don't know but now getting error

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

 
  • abinop
  • Member
  • Members
  • Join Date: 01-Apr 07
  • 57 posts

Posted 03 July 2007 - 08:50 PM #7

Don't know but now getting error

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


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: 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 "<p style=\"text-align:center;color:red;\">ERROR! - Tracking Number $tracking Not Found!</p> 
<p style=\"text-align:center;\"><a href=\"http://{$_SERVER['HTTP_HOST']}\">http://{$_SERVER['HTTP_HOST']}</a></p>"; 

} 
?>

Alexandros

 
  • Palmtop
  • Senior Member
  • Members
  • Join Date: 15-Feb 07
  • 310 posts

Posted 26 July 2007 - 05:29 PM #8

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

Thanks!
Francesco

 
  • grabbags
  • Senior Member
  • Members
  • Join Date: 14-Aug 07
  • 360 posts

Posted 14 August 2007 - 04:42 AM #9

That's what I need. Thank you! :D

 
  • mattzx11
  • Junior Member
  • Members
  • Join Date: 19-Jun 07
  • 25 posts

Posted 14 August 2007 - 02:50 PM #10

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

 
  • mattzx11
  • Junior Member
  • Members
  • Join Date: 19-Jun 07
  • 25 posts

Posted 14 August 2007 - 04:33 PM #11

Sorry for the confusion.

 
  • grabbags
  • Senior Member
  • Members
  • Join Date: 14-Aug 07
  • 360 posts

Posted 28 August 2007 - 07:54 PM #12

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