Package Tracking

Contrib type: 
Module
Status: 
Complete and working
Moderation: 
Not ready for moderation
Latest version: 
1.03

Downloads


Compatibility: 
Ubercart 1.x

Tracking information is probably the most important thing the customer is interested in seeing after an order is placed! The customer wants to know "Where's my stuff?", and you don't want him bugging you about it.

This module lets your customer (or you, the admin) track shipped packages. It uses a hook to interface with installed shipping methods, so it can support tracking packages sent by any carrier, provided the hook is implemented. This module comes with hooks pre-written for FedEx, UPS and USPS.

It works by modifying the user order history page (e.g. user/4/orders) to display a clickable tracking number (or numbers) associated with each order. The user can click on the number and get real-time tracking details for his merchandise.

I decided to display the tracking number on the order history page so the customer wouldn't have to drill down and look for the tracking number - it should be right up top, since it's the thing they care about most. (This active tracking link should also be available on any page where the tracking number appears, but to do that easily requires modifications to the core Ubercart modules.)

To Use:

Install uc_tracking module. Enable it at admin/build/modules.

Note that none of the shipping quote modules are listed as dependencies. That is not a mistake - this module checks for shipping methods implementing the hook. However, if you want to get tracking information for a specific carrier you MUST have that carrier's shipping quotes module installed, enabled, and configured with the correct authorization information (user id, password) needed to contact the carrier's server. It is NOT necessary to turn on shipping quotes for that carrier - simply enabling the module is sufficient.

When you ship a package, you need to choose the carrier from the select box at admin/store/orders/#/shipments/#/edit and enter a tracking number. The carriers displayed are chosen from the list of enabled shipping quotes modules. Tracking numbers will now show up as active links in the user order history page at user/#/orders. Clicking these links will contact the carrier's server to get and display real-time tracking information.

Implementation details:

No Ubercart core modules were harmed in the making of this contribution. However, some functions were ruthlessly overridden, resulting in some core modules with hurt feelings.

Specifically, the user/#/orders menu, defined in uc_order_menu(), was overridden to call my uc_tracking_order_history() function instead of the core uc_order_history() function. Likewise, the uc_shipping_shipment_edit form was altered to force the admin to select a carrier to associate with the entered tracking number ("Other" is also allowed...). This is necessary because to track a package, the code needs to know which carrier the tracking number is for.

This module defines hook_uc_tracking() and provides implementations for FedEx, UPS, and USPS tracking. Adding support for other carriers only requires implementation of that one hook.

hook_uc_tracking() returns an associative array in a specific format containing tracking details. The format of this array is described in the comments in uc_tracking.module.

The code is commented throughout.

It is intended that the implementations of hook_uc_tracking() provided for FedEx, UPS, and USPS will be moved into their corresponding shipping quotes modules and removed from this uc_tracking module.

Bug Fixes / Features added in version 1.03:

  1. Fixed typo in dependencies
  2. Added support for multiple packages per order

Bug Fixes / Features added in version 1.02:

  1. Added support for tracking USPS Delivery Confirmation numbers
  2. Added support for international shipping in the UPS and USPS functions

Bug Fixes / Features added in version 1.01:

  1. Fixed silly error in carrier selection box
  2. Added error handling for invalid tracking number

PreviewAttachmentSize
uc_tracking-1.03.tar.gz13.04 KB
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15453
Quote:No Ubercart core
Quote:

No Ubercart core modules were harmed in the making of this contribution. However, some functions were ruthlessly overridden, resulting in some core modules with hurt feelings.

I love it. Laughing out loud Thanks for posting up an awesome module and taking the time to do the write-up. You're already inspiring Lyle to bigger and better things. Eye-wink

rolandk's picture
Offline
Joined: 02/06/2008
Juice: 240
Canada Post ??

Can this mod be modified to work with Canada Post ?

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3229
Re: Canada Post ??

Yes, but this module doesn't need to be modified - it will work as-is. The Canada Post module just needs to implement hook_uc_tracking(). The details are in the README and the code.

<tr>.
rolandk's picture
Offline
Joined: 02/06/2008
Juice: 240
Re: Re: Canada Post ??

outstanding - thanks for that info. Maybe we should mention that in the readme on this mod's original posting here

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6855
Re: Package Tracking

I like the idea, but there's some changes I want to see before this gets included into core. Instead of using a hook, I think each shipping method should have its own tracking function. This would be listed as a 'track' callback much like 'quote' or 'ship'.

<?php
  $methods
= array(
   
'ups' => array(
     
//...
     
'track' => 'uc_ups_tracking',
     
//...
   
),
  );
?>

Similarly, I think the tracking functions ought to be chosen based on the shipment's shipping method rather than the carrier. The carrier is meant to be a human-readable text field, but the shipping method is more of an id for the shipping system. I've made a change to the shipping module to allow "manual" shipments to choose which method they will be identified with, even though no shipping label will be made.

I've attached a version of the tracking module that includes those changes. It still needs work because I got stuck while linking to the tracking page. I blame my lack of test data, and other priorities taking precedence. Anyway, the order pane that shows the tracking numbers ought to eventually go in the tracking module, which will link to the tracking results. If someone can make that happen, that'd be great.

I feel like I'm kind of doing a hit & run, but hopefully this can still be sorted out.

AttachmentSize
lyle_uc_tracking.tar.gz -- Needs more fixing. 8.37 KB
rolandk's picture
Offline
Joined: 02/06/2008
Juice: 240
Re: Re: Package Tracking

Lyle, I agree with your workflow. I'd love to see this mod developed to its completion.

I'm a little confused as to how to get yours or TR's mod to work.

Please can you give me the url of the shipping quote mod you refer to that needs to be pre-installed in order to get yours to work.

Will this work with the world quote mod available on these forums ?

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6855
Re: Re: Re: Package Tracking

It's the uc_shipping module. I added the change to the bazaar repository recently, so if you're getting those updates, you've already got it.

rolandk's picture
Offline
Joined: 02/06/2008
Juice: 240
Re: Re: Re: Re: Package Tracking

Sorry, I'm pretty noob to ubercart & bazaar and I can't seem to find it. Do you have the uc_shipping module url please ?

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3229
rolandk wrote: I'm a little
rolandk wrote:

I'm a little confused as to how to get yours or TR's mod to work.

Please can you give me the url of the shipping quote mod you refer to that needs to be pre-installed in order to get yours to work.

To get my module to work, unzip/untar it into site/all/modules then install it by checking the right box at admin/build/modules and pressing the "Save Configuration" button. That's all you have to do to install any module.

Regarding Lyle's changes - his version is an intermediate version between my standalone module and what he plans to put into core. I would not recommend using it at this point - it requires some manual changes to uc_ups, uc_fedex, and uc_usps, and doesn't implement the tracking links properly yet.

My module works just fine. When it gets modified and put into a core distribution, you can use the core version. Until then, just download the 1.03 version above.

<tr>.
rolandk's picture
Offline
Joined: 02/06/2008
Juice: 240
Re: rolandk wrote: I'm a little

thanks I got it installed.

I'm now stuck as to where/what exactly to amend to make it Canada Post compliant

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3229
Lyle wrote:Anyway, the order
Lyle wrote:

Anyway, the order pane that shows the tracking numbers ought to eventually go in the tracking module, which will link to the tracking results.

I like the uc_tracking_order_pane(). If that replaces uc_shipping_order_pane(), shouldn't the other stuff in uc_shipping for handling tracking numbers also be moved to uc_tracking? For example, instead of the form code in uc_shipment_shipment_edit(), uc_tracking_form_alter() could be used to add the fields for inputting a tracking number. Otherwise you'll be able to enter tracking numbers in uc_shipping but not see them on the order page unless uc_tracking is enabled. The two modules should be separate (with uc_tracking having a dependency on uc_shipping) or merged.

I've got your mods working - there were a number of bugs and other stuff I had to change. I'm still a little unsure about a couple of things:

What's the purpose of this code on line 79?

    if (is_numeric(arg(3))){
      $items[] = array('path' => 'admin/store/orders/'. arg(3) .'/track',
        'title' => t('Tracking'),
      );
    }
  }

I'm guessing it's because the order can be viewed either from admin/store/orders/# or from user/#/order/# ? But that doesn't matter since the link that does the callback doesn't care which page it's one. Or did you mean to make a tab next to the shippments and packages tabs?

Incidentally, why is the existing menu user/#/order/# and not user/#/orders/# (order vs. orders) - "orders" is used everywhere else...

The tracking information doesn't currently show up in the invoice view - I gather that's the point of 'show' => array('view', 'invoice', 'customer') - I'm not sure where to fix this.

I understand the purpose of uc_tracking_order_actions(), but I don't see that it gets called anywhere - what was your intention here? There doesn't seem to be a hook into uc_order_actions(), which is where I would expect this code to appear, and you wouldn't want to put it INTO uc_order_actions() because that would make uc_order depend on uc_tracking. Were you thinking of making some structural changes to uc_order?

<tr>.
TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3229
rolandk wrote:I'm now stuck
rolandk wrote:

I'm now stuck as to where/what exactly to amend to make it Canada Post compliant

You now have to create a function to do the Canada Post tracking. See the uc_tracking.module code for three examples - uc_ups_uc_tracking(), uc_usps_uc_tracking(), and uc_fedex_uc_tracking(). Lots of comments in the code describe the output needed from these hooks. Writing a function for Canada Post requires you to understand the Canada Post web services API for obtaining tracking information. I assume it will be very similar to the code written to do Canada Post shipping quotes, so you should start there and get the quotes working first then delve into the API docs to see how to properly form your tracking requests.

<tr>.
Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6855
Re: Lyle wrote:Anyway, the order

I couldn't decide whether the tracking module should be merged into shipping or if they should be kept separate. I kept trying to do both at once, and that's why I felt I couldn't get anything done.

I think I would like to keep the form elements and database handling of tracking numbers in shipping because it's a major piece of the returned data from the shipping APIs like UPS and FedEx. Hooking into that process is a tricky proposition, and not worth it in my mind. Even if they don't have the tracking module enabled, they should still be recorded. They just won't be used by Ãœbercart. The administrator can still see the tracking numbers when viewing the shipments. It should be reasonable to enable the tracking module to access the tracking information through the order pane and the tracking pages.

I would like the returned tracking information to be available to the store administrators, who might not have access to the user profiles. It keeps the breadcrumbs in the admin section automatically and keeps everything contained in one section. Maybe these aren't valid concerns though. It's not like I finished figuring out what I was doing with it.

"order" was probably a typo on someone's part. I'll ask Ryan to make sure there wasn't actually a good reason.

hook_order_actions() was added a few days ago to uc_order_actions. I decided that the shipping module needed links to the packages and shipments pages, as well as the tracking page.

I'm always working off the latest code. That's where all the fun happens. Smiling

rolandk's picture
Offline
Joined: 02/06/2008
Juice: 240
Re: rolandk wrote:I'm now stuck

From the Canada Post docu
Wherever your code sends a request to Sell Online please change the current IP address to
sellonline.canadapost.ca:30000

# For profile settings, change the IP address to http://sellonline.canadapost.ca/servlet/LogonServlet

apeee's picture
Offline
Joined: 12/11/2007
Juice: 128
Re: Package Tracking

How can I make this work with DHL?

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3229
Re: Re: Package Tracking

Read what I wrote above in response to the question about Canada Post.

Also, you will have to sign a non-disclosure agreement to get access to DHL's web tools API; if you write a hook for DHL you will not be able to share your code or make it public.

<tr>.
jccc's picture
Offline
Joined: 06/18/2008
Juice: 98
Getting a parse error--

I may have something not configured or not installed that I need first, but I'm not sure where to begin to look. Here's what I get after uploading:

Parse error: syntax error, unexpected '{' in /public_html/sites/all/modules/uc_tracking/uc_tracking.module on line 407

Line 407 is "try {" below:

  /* Include Details - 1 is TRUE */
  $request['TrackRequest']['IncludeDetailedScans'] = 1;

  //
  // Send the SOAP request to the FedEx server
  //
  try {
    $response = $client ->__soapCall("track", array('parameters' => $request));

    $details = array();
    $details['carrier'] = 'FedEx';
    $details['tracking_number'] = $tracking_number;

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3229
Re: Getting a parse error--

Are you using PHP 4 ? This won't work with PHP 4. That version of PHP is obsolete and unsupported.

<tr>.
jccc's picture
Offline
Joined: 06/18/2008
Juice: 98
Re: Re: Getting a parse error--

Nope: 5.2.3

jccc's picture
Offline
Joined: 06/18/2008
Juice: 98
Re: Re: Re: Getting a parse error--

Also if it helps: I'm on Drupal 5.7 and Ubercart 1.0 (basically what comes with the deluxe Ubercart download as of a couple days ago).

jccc's picture
Offline
Joined: 06/18/2008
Juice: 98
Re: Re: Re: Getting a parse error--

Blimey--my cPanel is lying to me. It says 5.2.3, yet running a phpinfo() tells me I am indeed running 4.4.6. Arg.

himagarwal's picture
Offline
Joined: 06/24/2008
Juice: 302
Re: Package Tracking

why FedEx is not showing in the "Carrier List"?

Has anyone implemented "package tracking" with DHL TrackIT XML API?

Can any shipping company having API for tracking be added to this module? I talked to one of my shipping company "aramex" in this regard for API. They will be sending me the API shipment tracking link and information? Can it be done?

Sorry, I'm no programmer. Is there a way (link/website/resource) from where I can learn to implement the hook() in the module for DHL and aramex?

any help will be great!

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3229
Re: Re: Package Tracking

From the README "...if you want to get tracking information for a specific carrier you MUST have that carrier's shipping quotes module installed, enabled, and configured with the correct authorization information (user id, password) needed to contact the carrier's server."

DHL has a proprietary API. You will need to sign an NDA to obtain the spec, and you are forbidden to allow anyone who hasn't signed the NDA access to your source code which their API. In practice, that means you can only distribute compiled source, precluding a PHP implementation. It's stupid, but that's what they say - allowing someone to see your source code is equivalent to disclosing a company secret.

Yes, you can easily add additional tracking methods to this module. The best way to do this is to use the example of the methods that are already in the module - modifying one of these for your shipping company is the simplest way to go.

<tr>.
himagarwal's picture
Offline
Joined: 06/24/2008
Juice: 302
Thanks. Can such kind of XML

Thanks.

Can such kind of XML file http://www.aramex.com/track_xml.asp?ShipmentNumber=5763299603 be implement directly in package tracking module for tracking, so that it shows in order history page?

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3229
Re: Thanks. Can such kind of XML

Yes.

<tr>.
TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3229
Moved to Drupal.org

This module is now hosted on Drupal.org at http://drupal.org/project/uc_tracking

Please post any issues or support requests on the above project page, not here.

<tr>.