*****************************
* Package Tracking Plus 2.1 *
* olsonsp4c 3-8-2008 *
* Released under the GPL *
*****************************

Credit to Wayne Wetterhahn, Jackie Edwards, Marcus R. Matos, Jared Call, and TCwho.
This contribution is a modified package based upon their work with my creative license.
If you found this contribution helpful and would like to make a donation, please visit
http://www.oscommerce.com/about.php/team and make a donation one one of the developers.


***************
* Description *
***************

This contribution allows osCommerce store owners to provide real-time UPS, USPS, Fedex,
and DHL package tracking to their customers. Store owners just enter the tracking number
into text boxes on the orders page inside admin. This should be done when updating the order
status to "Delivered" - afterwards, the customer will receive an email telling them the order
has been updated.

Email subjects will contain the order number and status while the text will include a
personalized, warm greeting. Comment text will not be included unless comments are added.
Included in the email is an invoice link which takes them to their account page on your
website as well as the clickable tracking number link(s) with the appropriate shipper
indicated (ie. USPS, UPS, Fedex, and/or DHL).

When a customer logs in to view the order invoice within their account history, the invoice
contains clickable tracking number links and a "Track" button. This will open a new window,
so the customer never leaves your website. Furthermore, in the admin, when the store owner
views a customer's order, there are now "Track" buttons next to each shipper's tracking number,
so that owners can track sent packages as easily as their customers.

You can have multiple shippers (ie. tracking numbers) for each order in any combination
(ie. you can have a package tracking number for both USPS and Fedex for the same order).
Furthermore, you can have UP TO TWO tracking numbers per shipper per order.

Lastly, you will find the order emails to be substantially warmer and more professional.

***SCREENSHOTS INCLUDED IN 2.0 PACKAGE***


************************************************** ************************
* Support Forum: http://forums.oscommerce.com/index.php?showtopic=170312 *
************************************************** ************************


********************
* Additional Notes *
********************

There are three additional modifications to this addon which can be found in the "mods" folder:

1. Order Editor (2.7.4) integration
2. Paypal Payment Module integration
3. USPS Cron job for delivered packages


*************************
* I could use help with *
*************************

Nothing at this point, but I'm open to input :)


*******************
* UPDATE 2.0->2.1 *
*******************

1. Add the contents of the update.sql to your mysql database. This works best if you use phpmyadmin.
This is REQUIRED in order this addon to function properly.
2. 2.1 is a major update, so you will need to re-edit nearly every file below (it took me a long time too)
3. Don't forget to re-upload the Cron Job mod and re-edit Order Editor mod files


********************
* PRE-INSTALLATION *
********************

You should make a BACKUP of your database AND all files listed below BEFORE
installing this addon (please do this, you won't regret it):

catalog/account_history_info.php
catalog/checkout_process.php
catalog/includes/languages/english/checkout_process.php
catalog/includes/languages/english/account_history_info.php
catalog/includes/classes/order.php
catalog/admin/orders.php
catalog/admin/includes/classes/order.php
catalog/admin/includes/languages/english/orders.php
catalog/includes/filenames.php
catalog/admin/includes/filenames.php
catalog/includes/database_tables.php
catalog/admin/includes/functions/html_output.php


****************
* INSTALLATION *
****************


*******************
* DATABASE UPDATE *
*******************

Add the contents of the tracking.sql to your mysql database. This works best if you use phpmyadmin.
This is REQUIRED in order this addon to function properly.


********************
* UPLOAD NEW FILES *
********************

catalog/includes/languages/english/images/buttons/button_track.php
catalog/admin/includes/languages/english/images/buttons/button_track.gif


**********
* STEP 1 *
**********

(SEE PRE-INSTALLATION prior to completing this step)

OPEN catalog/account_history_info.php:

***The following modification will enable your customers to view clickable tracking numbers at the bottom of an invoice when they login and click Account History to view an invoice as well as clickable "Track" buttons to the right.***

FIND this:



REPLACE with this:






















USPS(1):






USPS(2):





UPS(1):





UPS(2):





Fedex(1):





Fedex(2):





DHL(1):





DHL(2):


























USPS(1):




USPS(2):




UPS(1):




UPS(2):




Fedex(1):




Fedex(2):




DHL(1):



DHL(2):














**********
* STEP 2 *
**********

OPEN catalog/includes/database_tables.php

FIND this:

define('TABLE_TAX_RATES', 'tax_rates');

ADD this AFTER:

//Package Tracking Plus BEGIN
define('TABLE_USPS_TRACK_NUM', 'usps_track_num');
define('TABLE_USPS_TRACK_NUM', 'usps_track_num2');
define('TABLE_UPS_TRACK_NUM', 'ups_track_num');
define('TABLE_UPS_TRACK_NUM', 'ups_track_num2');
define('TABLE_FEDEX_TRACK_NUM', 'fedex_track_num');
define('TABLE_FEDEX_TRACK_NUM', 'fedex_track_num2');
define('TABLE_DHL_TRACK_NUM', 'dhl_track_num');
define('TABLE_DHL_TRACK_NUM', 'dhl_track_num2');
//Package Tracking Plus END


**********
* STEP 3 *
**********

OPEN catalog/includes/classes/order.php

FIND this:

$order_query = tep_db_query("select customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, currency, currency_value, date_purchased, orders_status, last_modified from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");

REPLACE with this:

//Package Tracking Plus BEGIN
$order_query = tep_db_query("select customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, usps_track_num, usps_track_num2, ups_track_num, ups_track_num2, fedex_track_num, fedex_track_num2, dhl_track_num, dhl_track_num2, currency, currency_value, date_purchased, orders_status, last_modified from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
//Package Tracking Plus END


***Note: The only change was the addition of usps_track_num, usps_track_num2, ups_track_num, ups_track_num2, fedex_track_num, fedex_track_num2, dhl_track_num, dhl_track_num2, to the query.


FIND this:

$this->info = array('currency' => $order['currency'],
'currency_value' => $order['currency_value'],
'payment_method' => $order['payment_method'],
'cc_type' => $order['cc_type'],
'cc_owner' => $order['cc_owner'],
'cc_number' => $order['cc_number'],
'cc_expires' => $order['cc_expires'],
'date_purchased' => $order['date_purchased'],
'orders_status' => $order_status['orders_status_name'],
'last_modified' => $order['last_modified'],
'total' => strip_tags($order_total['text']),
'shipping_method' => ((substr($shipping_method['title'], -1) == ':') ? substr(strip_tags($shipping_method['title']), 0, -1) : strip_tags($shipping_method['title'])));

INSERT this ABOVE the last line:

//Package Tracking Plus BEGIN
'usps_track_num' => $order['usps_track_num'],
'usps_track_num2' => $order['usps_track_num2'],
'ups_track_num' => $order['ups_track_num'],
'ups_track_num2' => $order['ups_track_num2'],
'fedex_track_num' => $order['fedex_track_num'],
'fedex_track_num2' => $order['fedex_track_num2'],
'dhl_track_num' => $order['dhl_track_num'],
'dhl_track_num2' => $order['dhl_track_num2'],
//Package Tracking Plus END

***Note: Make sure you follow the logical flow in the code. For example, if it is NOT the last line in the array, the line needs to end with a ",".
However, if the line IS the last line of the array, it needs to end with a ");".


**********
* STEP 4 *
**********

OPEN catalog/includes/languages/english/account_history_info.php

FIND this:

define('HEADING_SHIPPING_METHOD', 'Shipping Method');

ADD this AFTER:

//Package Tracking Plus BEGIN
define('HEADING_TRACKING', 'Order Tracking');
define('TEXT_NO_TRACKING_AVAILABLE', 'No tracking numbers are available yet.');
//Package Tracking Plus END


**********
* STEP 5 *
**********

***See the "mods" folder for integrating this step into Order Editor (2.7.4)***

OPEN catalog/admin/orders.php

FIND this:

$comments = tep_db_prepare_input($HTTP_POST_VARS['comments']);

ADD this AFTER:

//Package Tracking Plus BEGIN
$usps_track_num = tep_db_prepare_input($HTTP_POST_VARS['usps_track_num']);
$usps_track_num2 = tep_db_prepare_input($HTTP_POST_VARS['usps_track_num2']);
$ups_track_num = tep_db_prepare_input($HTTP_POST_VARS['ups_track_num']);
$ups_track_num2 = tep_db_prepare_input($HTTP_POST_VARS['ups_track_num2']);
$fedex_track_num = tep_db_prepare_input($HTTP_POST_VARS['fedex_track_num']);
$fedex_track_num2 = tep_db_prepare_input($HTTP_POST_VARS['fedex_track_num2']);
$dhl_track_num = tep_db_prepare_input($HTTP_POST_VARS['dhl_track_num']);
$dhl_track_num2 = tep_db_prepare_input($HTTP_POST_VARS['dhl_track_num2']);
//Package Tracking Plus END


FIND this:

$check_status_query = tep_db_query("select customers_name, customers_email_address, orders_status, date_purchased from " . TABLE_ORDERS . " where orders_id = '" . (int)$oID . "'");

REPLACE with this:

//Package Tracking Plus BEGIN
$check_status_query = tep_db_query("select customers_name, customers_email_address, orders_status, usps_track_num, usps_track_num2, ups_track_num, ups_track_num2, fedex_track_num, fedex_track_num2, dhl_track_num, dhl_track_num2, date_purchased from " . TABLE_ORDERS . " where orders_id = '" . (int)$oID . "'");
//Package Tracking Plus END

***Note: the only change was the addition of usps_track_num, usps_track_num2, ups_track_num, ups_track_num2, fedex_track_num, fedex_track_num2, dhl_track_num, dhl_track_num2, to the query.


***Note: The modification below will show clickable invoice number and tracking number in the customer emails.
In order to use this modification, Admin/Configuration/Use MIME HTML When Sending Emails must be set to "true".

FIND this:

$customer_notified = '0';
if (isset($HTTP_POST_VARS['notify']) && ($HTTP_POST_VARS['notify'] == 'on')) {
$notify_comments = '';
if (isset($HTTP_POST_VARS['notify_comments']) && ($HTTP_POST_VARS['notify_comments'] == 'on')) {
$notify_comments = sprintf(EMAIL_TEXT_COMMENTS_UPDATE, $comments) . "nn";
}

$email = STORE_NAME . "n" . EMAIL_SEPARATOR . "n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $oID . "n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_catalog_href_link(FILENAME_CATALOG_ACCOUNT_HIS TORY_INFO, 'order_id=' . $oID, 'SSL') . "n" . EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long($check_status['date_purchased']) . "nn" . $notify_comments . sprintf(EMAIL_TEXT_STATUS_UPDATE, $orders_status_array[$status]);

tep_mail($check_status['customers_name'], $check_status['customers_email_address'], EMAIL_TEXT_SUBJECT, $email, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

$customer_notified = '1';
}

REPLACE with this:

//Package Tracking Plus BEGIN
$customer_notified = '0';
if ($HTTP_POST_VARS['notify'] == 'on' & ($usps_track_num == '' & $usps_track_num2 == '' & $ups_track_num == '' & $ups_track_num2 == '' & $fedex_track_num == '' & $fedex_track_num2 == '' & $dhl_track_num == '' & $dhl_track_num2 == '' ) ) {
$notify_comments = '';
if ($HTTP_POST_VARS['notify_comments'] == 'on') {
$notify_comments = sprintf(EMAIL_TEXT_COMMENTS_UPDATE, $comments) . "n";
if ($comments == null)
$notify_comments = '';
}

$email = 'Dear ' . $check_status['customers_name'] . ',' . "nn" . STORE_NAME . "n" . EMAIL_SEPARATOR . "n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . (int)$oID . "n" . EMAIL_TEXT_INVOICE_URL . ' ' . "" . 'order_id=' . (int)$oID . "n" . EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long($check_status['date_purchased']) . "n" . EMAIL_SEPARATOR . "nnn" . $notify_comments . sprintf(EMAIL_TEXT_STATUS_UPDATE, $orders_status_array[$status]);
tep_mail($check_status['customers_name'], $check_status['customers_email_address'], STORE_NAME . ' ' . EMAIL_TEXT_SUBJECT_1. (int)$oID . EMAIL_TEXT_SUBJECT_2 . $orders_status_array[$status], $email, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
$customer_notified = '1';

}else if ($HTTP_POST_VARS['notify'] == 'on' & ($usps_track_num == '' or $usps_track_num2 == '' or $ups_track_num == '' or $ups_track_num2 == '' or $fedex_track_num == '' or $fedex_track_num2 == '' or $dhl_track_num == '' or $dhl_track_num2 == '' ) ) {
$notify_comments = '';
if ($HTTP_POST_VARS['notify_comments'] == 'on') {
$notify_comments = sprintf(EMAIL_TEXT_COMMENTS_UPDATE, $comments) . "n";
if ($comments == null)
$notify_comments = '';
}
if ($usps_track_num == null) {
$usps_text = '';
$usps_track = '';
}else{
$usps_text = 'USPS(1): ';
$usps_track_num_noblanks = str_replace(' ', '', $usps_track_num);
$usps_link = 'http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=' . $usps_track_num_noblanks;
$usps_track = '' . $usps_track_num . '' . "n";
}
if ($usps_track_num2 == null) {
$usps_text2 = '';
$usps_track2 = '';
}else{
$usps_text2 = 'USPS(2): ';
$usps_track_num2_noblanks = str_replace(' ', '', $usps_track_num2);
$usps_link2 = 'http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=' . $usps_track_num2_noblanks;
$usps_track2 = '' . $usps_track_num2 . '' . "n";
}
if ($ups_track_num == null) {
$ups_text = '';
$ups_track = '';
}else{
$ups_text = 'UPS(1): ';
$ups_track_num_noblanks = str_replace(' ', '', $ups_track_num);
$ups_link = 'http://wwwapps.ups.com/etracking/tracking.cgi?InquiryNumber1=' . $ups_track_num_noblanks . '&InquiryNumber2=&InquiryNumber3=&InquiryNumber4=& InquiryNumber5=&TypeOfInquiryNumber=T&UPS_HTML_Ver sion=3.0&IATA=us&Lang=en&submit=Track+Package ';
$ups_track = '' . $ups_track_num . '' . "n";
}
if ($ups_track_num2 == null) {
$ups_text2 = '';
$ups_track2 = '';
}else{
$ups_text2 = 'UPS(2): ';
$ups_track_num2_noblanks = str_replace(' ', '', $ups_track_num2);
$ups_link2 = 'http://wwwapps.ups.com/etracking/tracking.cgi?InquiryNumber1=' . $ups_track_num2_noblanks . '&InquiryNumber2=&InquiryNumber3=&InquiryNumber4=& InquiryNumber5=&TypeOfInquiryNumber=T&UPS_HTML_Ver sion=3.0&IATA=us&Lang=en&submit=Track+Package ';
$ups_track2 = '' . $ups_track_num2 . '' . "n";
}
if ($fedex_track_num == null) {
$fedex_text = '';
$fedex_track = '';
}else{
$fedex_text = 'Fedex(1): ';
$fedex_track_num_noblanks = str_replace(' ', '', $fedex_track_num);
$fedex_link = 'http://www.fedex.com/Tracking?tracknumbers=' . $fedex_track_num_noblanks . '&action=track&language=english&cntry_code=us';
$fedex_track = '' . $fedex_track_num . '' . "n";
}
if ($fedex_track_num2 == null) {
$fedex_text2 = '';
$fedex_track2 = '';
}else{
$fedex_text2 = 'Fedex(2): ';
$fedex_track_num2_noblanks = str_replace(' ', '', $fedex_track_num2);
$fedex_link2 = 'http://www.fedex.com/Tracking?tracknumbers=' . $fedex_track_num2_noblanks . '&action=track&language=english&cntry_code=us';
$fedex_track2 = '' . $fedex_track_num2 . '' . "n";
}
if ($dhl_track_num == null) {
$dhl_text = '';
$dhl_track = '';
}else{
$dhl_text = 'DHL(1): ';
$dhl_track_num_noblanks = str_replace(' ', '', $dhl_track_num);
$dhl_link = 'http://track.dhl-usa.com/atrknav.asp?ShipmentNumber=' . $dhl_track_num_noblanks . '&action=track&language=english&cntry_code=us';
$dhl_track = '' . $dhl_track_num . '' . "n";
}
if ($dhl_track_num2 == null) {
$dhl_text2 = '';
$dhl_track2 = '';
}else{
$dhl_text2 = 'DHL(2): ';
$dhl_track_num2_noblanks = str_replace(' ', '', $dhl_track_num2);
$dhl_link2 = 'http://track.dhl-usa.com/atrknav.asp?ShipmentNumber=' . $dhl_track_num2_noblanks . '&action=track&language=english&cntry_code=us';
$dhl_track2 = '' . $dhl_track_num2 . '' . "n";
}

$email = 'Dear ' . $check_status['customers_name'] . ',' . "nn" . STORE_NAME . "n" . EMAIL_SEPARATOR . "n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . (int)$oID . "n" . EMAIL_TEXT_INVOICE_URL . ' ' . "" . 'order_id=' . (int)$oID . "n" . EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long($check_status['date_purchased']) . "nnn" . EMAIL_SEPARATOR . "n" . EMAIL_TEXT_TRACKING_NUMBER . "n" . $usps_text . $usps_track . $usps_text2 . $usps_track2 . $ups_text . $ups_track . $ups_text2 . $ups_track2 . $fedex_text . $fedex_track . $fedex_text2 . $fedex_track2 . $dhl_text . $dhl_track . $dhl_text2 . $dhl_track2 . "nn" . $notify_comments . sprintf(EMAIL_TEXT_STATUS_UPDATE, $orders_status_array[$status]);
tep_mail($check_status['customers_name'], $check_status['customers_email_address'], STORE_NAME . ' ' . EMAIL_TEXT_SUBJECT_1. (int)$oID . EMAIL_TEXT_SUBJECT_2 . $orders_status_array[$status], $email, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
$customer_notified = '1';

}else if ($HTTP_POST_VARS['notify'] == 'on' & (tep_not_null($usps_track_num) & tep_not_null($usps_track_num2) & tep_not_null($ups_track_num) & tep_not_null($ups_track_num2) & tep_not_null($fedex_track_num) & tep_not_null($fedex_track_num2) & tep_not_null($dhl_track_num) & tep_not_null($dhl_track_num2) ) ) {
$notify_comments = '';
$usps_text = 'USPS(1): ';
$usps_track_num_noblanks = str_replace(' ', '', $usps_track_num);
$usps_link = 'http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=' . $usps_track_num_noblanks;
$usps_track = '' . $usps_track_num . '' . "n";
$usps_text2 = 'USPS(2): ';
$usps_track_num2_noblanks = str_replace(' ', '', $usps_track_num2);
$usps_link2 = 'http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=' . $usps_track_num2_noblanks;
$usps_track2 = '' . $usps_track_num2 . '' . "n";
$ups_text = 'UPS(1): ';
$ups_track_num_noblanks = str_replace(' ', '', $ups_track_num);
$ups_link = 'http://wwwapps.ups.com/etracking/tracking.cgi?InquiryNumber1=' . $ups_track_num_noblanks . '&InquiryNumber2=&InquiryNumber3=&InquiryNumber4=& InquiryNumber5=&TypeOfInquiryNumber=T&UPS_HTML_Ver sion=3.0&IATA=us&Lang=en&submit=Track+Package ';
$ups_track = '' . $ups_track_num . '' . "n";
$ups_text2 = 'UPS(2): ';
$ups_track_num2_noblanks = str_replace(' ', '', $ups_track_num2);
$ups_link2 = 'http://wwwapps.ups.com/etracking/tracking.cgi?InquiryNumber1=' . $ups_track_num2_noblanks . '&InquiryNumber2=&InquiryNumber3=&InquiryNumber4=& InquiryNumber5=&TypeOfInquiryNumber=T&UPS_HTML_Ver sion=3.0&IATA=us&Lang=en&submit=Track+Package ';
$ups_track2 = '' . $ups_track_num2 . '' . "n";
$fedex_text = 'Fedex(1): ';
$fedex_track_num_noblanks = str_replace(' ', '', $fedex_track_num);
$fedex_link = 'http://www.fedex.com/Tracking?tracknumbers=' . $fedex_track_num_noblanks . '&action=track&language=english&cntry_code=us';
$fedex_track = '' . $fedex_track_num . '' . "n";
$fedex_text2 = 'Fedex(2): ';
$fedex_track_num2_noblanks = str_replace(' ', '', $fedex_track_num2);
$fedex_link2 = 'http://www.fedex.com/Tracking?tracknumbers=' . $fedex_track_num2_noblanks . '&action=track&language=english&cntry_code=us';
$fedex_track2 = '' . $fedex_track_num2 . '' . "n";
$dhl_text = 'DHL(1): ';
$dhl_track_num_noblanks = str_replace(' ', '', $dhl_track_num);
$dhl_link = 'http://track.dhl-usa.com/atrknav.asp?ShipmentNumber=' . $dhl_track_num_noblanks . '&action=track&language=english&cntry_code=us';
$dhl_track = '' . $dhl_track_num . '' . "n";
$dhl_text2 = 'DHL(2): ';
$dhl_track_num2_noblanks = str_replace(' ', '', $dhl_track_num2);
$dhl_link2 = 'http://track.dhl-usa.com/atrknav.asp?ShipmentNumber=' . $dhl_track_num2_noblanks . '&action=track&language=english&cntry_code=us';
$dhl_track2 = '' . $dhl_track_num2 . '' . "n";
if ($HTTP_POST_VARS['notify_comments'] == 'on') {
$notify_comments = sprintf(EMAIL_TEXT_COMMENTS_UPDATE, $comments) . "n";
if ($comments == null)
$notify_comments = '';
}

$email = 'Dear ' . $check_status['customers_name'] . ',' . "nn" . STORE_NAME . "n" . EMAIL_SEPARATOR . "n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . (int)$oID . "n" . EMAIL_TEXT_INVOICE_URL . ' ' . "" . 'order_id=' . (int)$oID . "n" . EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long($check_status['date_purchased']) . "nnn" . EMAIL_SEPARATOR . "n" . EMAIL_TEXT_TRACKING_NUMBER . "n" . $usps_text . $usps_track . $usps_text2 . $usps_track2 . $ups_text . $ups_track . $ups_text2 . $ups_track2 . $fedex_text . $fedex_track . $fedex_text2 . $fedex_track2 . $dhl_text . $dhl_track . $dhl_text2 . $dhl_track2 . "nn" . $notify_comments . sprintf(EMAIL_TEXT_STATUS_UPDATE, $orders_status_array[$status]);
tep_mail($check_status['customers_name'], $check_status['customers_email_address'], STORE_NAME . ' ' . EMAIL_TEXT_SUBJECT_1 . (int)$oID . EMAIL_TEXT_SUBJECT_2 . $orders_status_array[$status], $email, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
$customer_notified = '1';
}
//Package Tracking Plus END

tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified, comments) values ('" . (int)$oID . "', '" . tep_db_input($status) . "', now(), '" . tep_db_input($customer_notified) . "', '" . tep_db_input($comments) . "')");

$order_updated = true;
}


FIND this:

tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified, comments) values ('" . (int)$oID . "', '" . tep_db_input($status) . "', now(), '" . tep_db_input($customer_notified) . "', '" . tep_db_input($comments) . "')");

$order_updated = true;
}

ADD this AFTER:

//Package Tracking Plus BEGIN
tep_db_query("update " . TABLE_ORDERS . " set usps_track_num = '" . tep_db_input($usps_track_num) . "' where orders_id = '" . tep_db_input($oID) . "'");
tep_db_query("update " . TABLE_ORDERS . " set usps_track_num2 = '" . tep_db_input($usps_track_num2) . "' where orders_id = '" . tep_db_input($oID) . "'");
tep_db_query("update " . TABLE_ORDERS . " set ups_track_num = '" . tep_db_input($ups_track_num) . "' where orders_id = '" . tep_db_input($oID) . "'");
tep_db_query("update " . TABLE_ORDERS . " set ups_track_num2 = '" . tep_db_input($ups_track_num2) . "' where orders_id = '" . tep_db_input($oID) . "'");
tep_db_query("update " . TABLE_ORDERS . " set fedex_track_num = '" . tep_db_input($fedex_track_num) . "' where orders_id = '" . tep_db_input($oID) . "'");
tep_db_query("update " . TABLE_ORDERS . " set fedex_track_num2 = '" . tep_db_input($fedex_track_num2) . "' where orders_id = '" . tep_db_input($oID) . "'");
tep_db_query("update " . TABLE_ORDERS . " set dhl_track_num = '" . tep_db_input($dhl_track_num) . "' where orders_id = '" . tep_db_input($oID) . "'");
tep_db_query("update " . TABLE_ORDERS . " set dhl_track_num2 = '" . tep_db_input($dhl_track_num2) . "' where orders_id = '" . tep_db_input($oID) . "'");
$order_updated = true;
//Package Tracking Plus END


***The following adds clickable "Track" buttons to the right of each tracking number box***

FIND this:








ADD this AFTER:

















































**********
* STEP 6 *
**********

***See the "mods" folder for integrating this step into Order Editor (2.7.4)***

OPEN catalog/admin/includes/languages/english/orders.php

FIND this:

define('TABLE_HEADING_TOTAL_INCLUDING_TAX', 'Total (inc)');

And ADD this AFTER:

//Package Tracking Plus BEGIN
define('TABLE_HEADING_USPS_TRACKING', 'USPS Tracking Number(s)');
define('TABLE_HEADING_UPS_TRACKING', 'UPS Tracking Number(s)');
define('TABLE_HEADING_FEDEX_TRACKING', 'Fedex Tracking Number(s)');
define('TABLE_HEADING_DHL_TRACKING', 'DHL Tracking Number(s)');
//Package Tracking Plus END


FIND this:

define('EMAIL_SEPARATOR', '------------------------------------------------------');
define('EMAIL_TEXT_SUBJECT', 'Order Update');
define('EMAIL_TEXT_ORDER_NUMBER', 'Order Number:');
define('EMAIL_TEXT_INVOICE_URL', 'Detailed Invoice:');
define('EMAIL_TEXT_DATE_ORDERED', 'Date Ordered:');
define('EMAIL_TEXT_STATUS_UPDATE', 'Your order has been updated to the following status.' . "nn" . 'New status: %s' . "nn" . 'Please reply to this email if you have any questions.' . "n");
define('EMAIL_TEXT_COMMENTS_UPDATE', 'The comments for your order are' . "nn%snn");

And REPLACE with this (customize):

//Package Tracking Plus BEGIN
define('EMAIL_SEPARATOR', '------------------------------------------------------');
define('EMAIL_TEXT_SUBJECT_1', ' Order ');
define('EMAIL_TEXT_SUBJECT_2', ': ');
define('EMAIL_TEXT_ORDER_NUMBER', 'Order Number:');
define('EMAIL_TEXT_INVOICE_URL', 'Detailed Invoice:');
define('EMAIL_TEXT_DATE_ORDERED', 'Date Ordered:');
define('EMAIL_TEXT_STATUS_UPDATE', 'Your order has been updated to the following status: %s' . "nn" . 'If necessary, you may update your order directly by following the link above (login required). If you have questions or comments, please reply to this email.' . "nn" . 'With warm regards from your friends at ' . STORE_NAME . "n");
define('EMAIL_TEXT_TRACKING_NUMBER', 'Package tracking number(s):');
define('EMAIL_TEXT_COMMENTS_UPDATE', 'The comments for your order are:' . "nn%snn");
//Package Tracking Plus END


**********
* STEP 7 *
**********

***See the "mods" folder for integrating this step into Order Editor (2.7.4)***

OPEN catalog/admin/includes/classes/order.php

FIND this:

$order_query = tep_db_query("select customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, currency, currency_value, date_purchased, orders_status, last_modified from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");

And REPLACE it with this:

//Package Tracking Plus BEGIN
$order_query = tep_db_query("select customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, usps_track_num, usps_track_num2, ups_track_num, ups_track_num2, fedex_track_num, fedex_track_num2, dhl_track_num, dhl_track_num2, currency, currency_value, date_purchased, orders_status, last_modified from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
//Package Tracking Plus END

***Note: the only change was the addition of usps_track_num, usps_track_num2, ups_track_num, ups_track_num2, fedex_track_num, fedex_track_num2, dhl_track_num, dhl_track_num2, to the query.


FIND this:

$this->info = array('currency' => $order['currency'],
'currency_value' => $order['currency_value'],
'payment_method' => $order['payment_method'],
'cc_type' => $order['cc_type'],
'cc_owner' => $order['cc_owner'],
'cc_number' => $order['cc_number'],
'cc_expires' => $order['cc_expires'],
'date_purchased' => $order['date_purchased'],
'orders_status' => $order['orders_status'],
'last_modified' => $order['last_modified']);

And INSERT this ABOVE the last line:

//Package Tracking Plus BEGIN
'usps_track_num' => $order['usps_track_num'],
'usps_track_num2' => $order['usps_track_num2'],
'ups_track_num' => $order['ups_track_num'],
'ups_track_num2' => $order['ups_track_num2'],
'fedex_track_num' => $order['fedex_track_num'],
'fedex_track_num2' => $order['fedex_track_num2'],
'dhl_track_num' => $order['dhl_track_num'],
'dhl_track_num2' => $order['dhl_track_num2'],
//Package Tracking Plus END

***Note: Make sure you follow the logical flow in the code. For example, if it is NOT the last line in the array, the line needs to end with a ",".
However, if the line IS the last line of the array, it needs to end with a ");".


**********
* STEP 8 *
**********

OPEN catalog/admin/includes/functions/html_output.php

FIND this:

////
// Output a form textarea field
function tep_draw_textarea_field($name, $wrap, $width, $height, $text = '', $parameters = '', $reinsert_value = true) {
global $HTTP_GET_VARS, $HTTP_POST_VARS;

$field = '';

if ( ($reinsert_value == true) && ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) ) {
if (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) {
$field .= tep_output_string_protected(stripslashes($HTTP_GET _VARS[$name]));
} elseif (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) {
$field .= tep_output_string_protected(stripslashes($HTTP_POS T_VARS[$name]));
}
} elseif (tep_not_null($text)) {
$field .= tep_output_string_protected($text);
}

$field .= '';

return $field;
}

ADD this AFTER:

//Package Tracking Plus BEGIN
////
// Output a form textbox field
function tep_draw_textbox_field($name, $size, $numchar, $value = '', $params = '', $reinsert_value = true) {
$field = '';

return $field;
}
//Package Tracking Plus END


**********
* STEP 9 *
**********

OPEN catalog/checkout_process.php

***Note: If you any Paypal module/addon, you MUST ALSO merge the following changes into the primary
paypal file (ie. paypal.php or similar file depending on which addon you are using).
See the installation instructions in the "mod" folder for details.

FIND this:

// lets start with the email confirmation
$email_order = STORE_NAME . "n" .

REPLACE with this:

//Package Tracking Plus BEGIN
// lets start with the email confirmation
$email_order = EMAIL_TEXT_GREETING . "n" .
EMAIL_SEPARATOR . "n" .
STORE_NAME . EMAIL_INVOICE . "n" .
//Package Tracking Plus END


FIND this:

EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $insert_id, 'SSL', false) . "n" .

REPLACE with this:

//Package Tracking Plus BEGIN
EMAIL_TEXT_INVOICE_URL . ' ' . "" . 'order_id=' . $insert_id . "n" .
//Package Tracking Plus END


FIND this:

tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

REPLACE with this:

//Package Tracking Plus BEGIN
tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], STORE_NAME . ' ' . EMAIL_TEXT_SUBJECT_1 . ' ' . $insert_id . ' ' . EMAIL_TEXT_SUBJECT_2 , $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
//Package Tracking Plus END


FIND this:

tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

REPLACE with this:

//Package Tracking Plus BEGIN
tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, STORE_NAME . ' ' . EMAIL_TEXT_SUBJECT_1 . ' ' . $insert_id . ' ' .EMAIL_TEXT_SUBJECT_2, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
//Package Tracking Plus END


***********
* STEP 10 *
***********

OPEN catalog/includes/languages/english/checkout_process.php

FIND this:

define('EMAIL_TEXT_SUBJECT', 'Order Process');

REPLACE with this (customize):

//Package Tracking Plus BEGIN
//define('EMAIL_TEXT_SUBJECT', 'Order Process');
define('EMAIL_TEXT_GREETING', 'Thank you so much for ordering from ' . STORE_NAME . '! Below is an invoice of your order for your records. If necessary, you may update your order directly by following the link below (login required). If you have questions or comments, please reply to this email.' . "nn" . 'With warm regards from your friends at ' . STORE_NAME . "n");
define('EMAIL_TEXT_SUBJECT_1', ' Order');
define('EMAIL_TEXT_SUBJECT_2', 'has been received.');
//Package Tracking Plus END


FIND this:

define('EMAIL_SEPARATOR', '------------------------------------------------------');
define('TEXT_EMAIL_VIA', 'via');

And REPLACE with this:

//Package Tracking Plus BEGIN
define('EMAIL_SEPARATOR', '------------------------------------------------------');
define('EMAIL_INVOICE', ' Invoice');
define('TEXT_EMAIL_VIA', 'via');
//Package Tracking Plus END




******************
* OPTIONAL STEPS *
******************

You can optionally add a webpage where any user can track UPS, USPS, Fedex, and DHL packages.
No need to login or have an account at your store. This adds a link to your information column (left side)
and directs to a page that displays forms where thay can enter tracking numbers.
The results open in a new window so they never leave your store.


*******************
* OPTIONAL STEP 1 *
*******************

OPEN catalog/includes/filenames.php

FIND this:

define('FILENAME_TELL_A_FRIEND', 'tell_a_friend.php');

ADD this AFTER:

// Package Tracking Plus BEGIN
define('FILENAME_TRACKING', 'tracking.php');
// Package Tracking Plus END


*******************
* OPTIONAL STEP 2 *
*******************

OPEN catalog/admin/includes/filenames.php

FIND this:

define('FILENAME_CATALOG_ACCOUNT_HISTORY_INFO', 'account_history_info.php');

ADD this AFTER:

//Package Tracking Plus BEGIN
define('FILENAME_CATALOG_TRACKING_NUMBER', 'tracking.php');
//Package Tracking Plus END


*******************
* OPTIONAL STEP 3 *
*******************

OPEN catalog/includes/boxes/information.php

FIND this:

'' . BOX_INFORMATION_CONDITIONS . '
' .

ADD this AFTER:

//Package Tracking Plus BEGIN
'' . BOX_INFORMATION_TRACKING . '
' .
//Package Tracking Plus END


*******************
* OPTIONAL STEP 4 *
*******************

OPEN catalog/includes/languages/english.php

FIND this:

define('HEADER_TITLE_LOGIN', 'Log In');

ADD this AFTER:

//Package Tracking Plus BEGIN
define('HEADER_TITLE_TRACKING', 'Package Tracking');
//Package Tracking Plus END


FIND this:

define('BOX_INFORMATION_SHIPPING', 'Shipping & Returns');

ADD this AFTER:

//Package Tracking Plus BEGIN
define('BOX_INFORMATION_TRACKING', 'Package Tracking');
//Package Tracking Plus END


*******************
* OPTIONAL STEP 5 *
*******************

Upload the following files to your server.

catalog/tracking.php
catalog/includes/languages/english/tracking.php

Test it by going to your store, click on the link that says "Package Tracking" (left side of page),
and insert tracking numbers into the forms, click the "Track" button. A new window should open with the tracking results.


*******************
* Troubleshooting *
*******************

Make one test order and check email to receive confirmation.

***Test tracking numbers***

Obtain test USPS, UPS, Fedex, and DHL tracking numbers

In Admin->Orders:
1. Add a comment
2. Choose "update"
3. Check email to check the existence of links, correct formatting, etc...
4. Add a tracking number.
5. Change the status to processing (or the like).
6. Choose "update"
7. Check email to check the existence of links, correct formatting, tracking number, etc...
8. Add a comment
9. Choose "update"
10. Check email to check the existence of links, correct formatting, tracking number, etc...
11. Add a tracking number (2 tracking numbers).
12. Change the status to shipped (or the like).
13. Choose "update"
14. Check email to check the existence of links, correct formatting, tracking number, etc...
15. Add a comment
16. Choose "update"
17. Check email to check the existence of links, correct formatting, tracking number, etc...
18. Add a tracking number (3 tracking numbers).
19. Change the status to processing (or the like).
20. Choose "update"
21. Check email to check the existence of links, correct formatting, tracking number, etc...
22. Add a comment
23. Choose "update"
24. Check email to check the existence of links, correct formatting, tracking number, etc...
25. Change the status to shipping (or the like).
26. Check email to check the existence of links, correct formatting, tracking number, etc...
27. You can CONTINUE this process with additional tracking numbers.
28. Login to your store account.
29. Click on "Account Overview" or "Account History" or the like.
30. Choose an order and view the details.
31. You should see all comments as well as have at least 3 clickable links which should
open new pages with correct tracking info. Test all links.

Finished!

***Note: If any of the tests do not work as stated, either you or I made a mistake somewhere.
***Double check*** to ensure you did not miss a step in the installation.


*******************
* Version History *
*******************

Changes since v2.0
------------------
* Added support for 2 packages per carrier per order (this effect more than 1/2 of the code)
* Removed Fedex Freight as Fedex now uses the same link for both Fedex and Fedex Freight (eliminated redundancy) [effects most edits and tracking.php files]
* Removed the clickable link from admin/orders.php because when having multiple tracking numbers per order, this is no longer necessary (tracking buttons are better)
* Fixed various typos throughout (ie. Package tracking instead of Order Tracking in the information box, etc.)
* Updated Order Editor and USPS Cron Job mods to reflect multiple package tracking changes
* Updated the description to accurately reflect what this addon is capable of


Changes since v1.5
------------------
* Created a stock osCommerce installation set of files for uploading to an UNMODIFIED site.
* Modified the instructions to be compatible with osCommerce 2.2 Milestone 2 Update 060817.
* Streamlined the instructions yet further and made a few further clarifications.
* Removed unnecessary line breaks for tracking information in emails.
* Removed unnecessary lines in admin/orders.php and recoded tracking number email line
breaks so that email tracking information line breaks format properly.
* I had accidentally deleted the "Comments" form in admin/orders.php in the integrated files
included for upload on an UNMODIFIED osCommerce store. It has now been corrected.
* Updated the Fedex Tracking link in admin/orders.php and catalog/includes/languages/english/tracking.php
and catalog/account_history_info.php (thanks to onnig)
* Added an optional cron job which uses the USPS api to automatically check if orders have been delivered.
If they have been delivered the database is updated accordingly to reflect this status. (thanks to crimble crumble)
* Substantial revamping of instruction
* Removal of unmodified store instructions
* Finally removed the "comments" database query error
* Reformatted the "tracking.php" page
* Reformatted the "orders.php" input boxes
* Added Paypal addon instructions based on osC team addon
* Updated for osC RC2a


Changes since v1.4
------------------
This update adds instructions on how to integrate this contribution with the Order Editor Contribution
and adds a customer greeting to the initial email from checkout_process.
* Steps 5,6,&7 have been modified and reordered for integration with Order Editor (2.7.4 by djmonkey).
I've included instructions for those wi

More...