Hi,

I was wondering if there is some kind of Track & Trace module available for Drupal. Something like the track & trace functionality DHL or US Postal service offers you.

So the customer gets an unique key. He can go to a form and enters the unique key/id and get's some information back. The key cannot be the node id or something, because you don't want that another visitor (than the owner) can track the status of an order.

I guess it isn't too hard to build this in Drupal, but I was just wondering if there is already something like this out there.

Thanks!

Paul

Comments

mcfilms’s picture

What about some of the support ticket modules?

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

alex_shapka’s picture

I don't remember any Drupal module offering this kind of functionality, but you are right that it shouldn't be hard to build it on Drupal. You even could go without writing a separate custom module, by generating random tracking number and feeding CCK field with it.

Of course, in this case you have to take care of search to index your CCK as soon as possible. Afaik core search module for Drupal 6 does not search CCK fields, you have to either use Apache Solr Search or install another module which provides CCK field search functionality.

calebm12’s picture

very interested in this. just logged on to ask the exact same question.

I would add that you should not have to be an authenticated user to track and trace. Maybe just have them enter an email address and a code, and if they match, return the status.

pvanerk’s picture

Yes, that was what I was thinking. You can generate an unique code to populate a cck field. Send the generated code to a person (can be an anonymous user in Drupal). Just make a form or a view which take the unique code and email address as input and return the status.

I will keep you guys posted.

pvanerk’s picture

I have build a track & trace option for our products. Below I will outline how the solution looks like. Thanks to ablommers for the trick for bypassing the security for a view.

CCK fields:
General noticeWe use one field for all our computed code. Say for example: field_operations_ccktype (type: Computed). In this field we put all our computed code for the other fields.

Add field:
Unique ID (Track and Trace) / field_unique_id / Text

Add computed code to the field_operations_ccktype:
// ---------------------------------------------------------
//  Set Unique ID for Track & Trace (one time)
//--------------------------------------------------------
if ($node->field_unique_id [0]['value'] == null)
{
$random_id_length = 20; //set the random id length 
$rnd_id = crypt(uniqid(rand(),1)); //generate a random id encrypt it and store it in $rnd_id 
$rnd_id = strip_tags(stripslashes($rnd_id)); //to remove any slashes that might have come 
$rnd_id = str_replace(".","",$rnd_id); //Removing any . or / and reversing the string 
$rnd_id = strrev(str_replace("/","",$rnd_id)); 
$rnd_id = substr($rnd_id,0,$random_id_length); //take 20 characters from the $rnd_id 
$node->field_unique_id [0]['value'] = $rnd_id;
}

So the code below, populates the field_unque_id.
In the field_operations_ccktype there is also other php code available to populate other fields. By doing it this way (putting all the code in one field) you have all your code in one place. This is easier for migration.

Views
I have created a view where I display certain CCK fields (like ID and workflow status). The argument I use in the view is the field_unique_id. You can also specify this as a filter.

Security
I had some trouble with the security of nodes. In our applications we use the Node access node reference and Node access user reference for the security of our nodes.
This setup enables us to make sure people only can see the nods they are entitled to. However, anonymous users cannot see anything on our Portal. For the Track and Trace option, you don't want people to log in. They should see the status of their ccall or instance without having an account.

The Views module will only show the nodes you are entitled to. But for the Track and Trace module, you want people to see the status of the node even if they have no access to this node.

There is an option in the Views module to do this, however it is not documented anywhere so it took a while to find out.

In the Views module,
go to "Basic Settings", "Access" and select "Role" and "Anonymous user".
go to "Query settings" and select "Disable SQL rewriting".

Now the view will display the nodes ignoring the security. You can not open the node itself because then the security kicks back in. So this only enables you to show some fields anonymous users have rights to, without showing the full node.

Remarks
When a new instance is created, an email is sent to the person who can track & trace the instance. In the email an URL is given to the path of the view (including the unique id). By clicking on this URL, he is redirected to the view and the status of the instance is shown on the screen. He is not enabled to see anything else on the Portal because of our strict security policies (he is an anonymous user and they aren't allowed to see any information on the Portal.

calebm12’s picture

This looks excellent. Thanks for sharing. I am trying to wrap my head around how to implement this. Would you mind walking me through a bit?

If i was to start from scratch I am assuming.
1. Create a content type (call it Status)
2. Add the following CCK fields: Client Name (text), Client email (email), Unique ID, Service Status (maybe this could be a multi-field group allowing unlimited groups of date, status, and narrative).
3. Add the Operations CCKType field (computed). Use the code you reference above.
4. Create a view with the fields you want displayed, and change the "basic settings" and "query settings" as you have specified.

From there I am lost. I am not sure what you mean by "when a new instance is created". Do I have to use rules to send the email to the client. Do i create a node and then edit it with status updates? Do i need the node security modules you listed as using?

pvanerk’s picture

Hi,

Let me first elaborate a bit more on the setup we use. We build applications which use Drupal as the Portal and NetXq (http://www.streamconsulting.nl/?q=content/NetXq - we are working on a new website :-)) as workflow engine. The workflow engine takes care of sending emails when the instances are triggered.

For sending email, you can also use the Rules engine which is available as a Drupal module.

Rules
So let's say you are using the Rules module to send mails. I will briefly discuss how to send up the rules engine to send mails, for more information check the Rules documentation.
1. Create a Triggered using the Event: "After saving new content" (or any other event of course).
2. Add conditions to the newly created triggered rule (say for instance "Content has type" to only send mails for certain content type).
3. Add an action - "Send a mail to a user". Use tokens to put the field_unique_code in the mail. Make a reference in the mail to the view you created before. The filter should have a filter for field_unique_id so users can enter the code, or you can sue arguments (see Views documentation).

Procedure
So, when a customer new content, he needs to fill in his email address. He saves the node. While saving the node, the computed code calculates a unqiue id (and stores it in field_unique_id).
After saving the node, the Rules engine kicks in. He sees a new node is saved, so an emal is sent to the user. The email containd\s the field_unique_id and a reference to the view.

When somebody changes the status (in your case Service Status) of the node (for our products, this is the workflow status, somebody can trigger the node to another place and the workflow status changes), the field_service_status gets a new value. When the customer opens the Track 'n Trace page, he can enter the unqiue code and the latest Service Status is shown.

There is no need to use the security modules I mentioned. We use this to make sure nodes caan only be seen by people who have the proper rights for it. Propably in your case, it is sufficient to use the standard Drupal security (based on roles).

Good luck!

calebm12’s picture

Greatly appreciate the elaboration. Let me give this a try and post back!

calebm12’s picture

been working through this and cant seem to get the computed field to work.

for my content type i created:
1) field_unique_id (type: integer)
2) field_status_operations (type: computed)
I have set the computed field up to be as follows:
Required: No
Number of Values: 1
Computed code:

<?php
if ($node->field_unique_id [0]['value'] == null)
{
$random_id_length = 20; //set the random id length
$rnd_id = crypt(uniqid(rand(),1)); //generate a random id encrypt it and store it in $rnd_id
$rnd_id = strip_tags(stripslashes($rnd_id)); //to remove any slashes that might have come
$rnd_id = str_replace(".","",$rnd_id); //Removing any . or / and reversing the string
$rnd_id = strrev(str_replace("/","",$rnd_id));
$rnd_id = substr($rnd_id,0,$random_id_length); //take 20 characters from the $rnd_id
$node->field_unique_id [0]['value'] = $rnd_id;
}
?>

Display Formet: $display = $node_field_item['value'];
Store using the database settings below: Yes
Data Type: Varchar
Default Value: Null
Not Null: No
Sortable: Yes

When i create a node, the uniqueid doesn't get populated with anything.

pvanerk’s picture

Hi,

The field_unique_id should be a text field. De random ID generates consists of A-Z, a-z, and 0-9.

Hope this will help, let me know if you need more help.

calebm12’s picture

Paul

thanks for your help.
i changed the field to text and its still not populating. i am wondering if the computed field is not firing?
All i have in the computed code box is what i posted above.

pvanerk’s picture

The only thing that is different in my setup is that I have Data Length 1, but I guess it is the same in your setup.

Let me do some tests with your code. I will get back to you as soon as possible.

pvanerk’s picture

Your setup looks exactly as mine. You shouldn't include the tags

<?php
?>

in your computed code, but I guess you already know that.

So you should put this code exactly as is stated below (without the php tags) in your computed code block

// ---------------------------------------------------------
//  Set Unique ID for Track & Trace (one time)
//--------------------------------------------------------

if ($node->field_unique_id [0]['value'] == null)
{
//set the random id length 
$random_id_length = 20; 
//generate a random id encrypt it and store it in $rnd_id 
$rnd_id = crypt(uniqid(rand(),1)); 
//to remove any slashes that might have come 
$rnd_id = strip_tags(stripslashes($rnd_id)); 
//Removing any . or / and reversing the string 
$rnd_id = str_replace(".","",$rnd_id); 
$rnd_id = strrev(str_replace("/","",$rnd_id)); 
//take 20 characters from the $rnd_id 
$rnd_id = substr($rnd_id,0,$random_id_length); 
$node->field_unique_id [0]['value'] = $rnd_id;
}
calebm12’s picture

Got it! I deleted the field and tried it again. Its populating now!

Next step: to figure out the view filters.

Thanks so much.