DHL

Modules, Add-ons and custom code that's more than just a quick hack or Mod.
Post Reply
gaz
Confirmed
Confirmed
Posts: 30
Joined: Mon Jun 22, 2009 1:27 pm

DHL

Post by gaz »

Are any of you using DHL for shipping.

I'm always having to check up on the status of a delivery which can be a really cumbersome process:

view orders-> customer -> login as customer -> account -> order status -> view order status - dhl tracking page

I did a quick hack to add the view order status link to the view orders page but even that is a pain so I've taken it a step further.

Note this only works if you only use one shipper at the moment.

Using a php to parse the DHL tracking page and some simple JQuery the status shows up nicely after a simple button click
If anyone is interested in the code let me know and I'll send it accross.

It's hardly a super streamlined code but it works for me!

Image
Tony Barnes
Posts: 744
Joined: Thu Jun 18, 2009 8:59 am

Re: DHL

Post by Tony Barnes »

Nice little hack :D
gaz
Confirmed
Confirmed
Posts: 30
Joined: Mon Jun 22, 2009 1:27 pm

Re: DHL

Post by gaz »

Give it a go.

I don't know how to check who it was shipped by as I use Free shipping and include the shipping costs in my prices, so I have no idea how it displays on the orders screen.

I'm sure it's simple enough, I'll have to set up extra shipping options and try it.

If it's just one shipper you're using its easy enough to modify.

The php loads the tracking webpage and passes the tracking number from the admin panel into the webpage url.

Eg.
Then it parses the webpage and returns the summary status text.
I spent two days trying to get the regex to work and failed miserably so I went for the old school explode string. Plus not having to change regex's makes it easier to mod the script to work with your page.
Hold your flames, if you come up with something better share it.

Granted this isn't lightning quick but it works just fine.

/www/modules/notification/shipping/status.php
<?php

$track = $_GET['track'];

function get_web_page( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => "Delivery Checker", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);

$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );

$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}

/*
change url to your shippers tracking page substituting the tracking number
for ".$track." this will pass in the var from the order page in ISC

*/

$url = "http://www.dhl.co.uk/publish/gb/en/eshi ... =fasttrack";

$content = get_web_page($url);
$content = $content['content'];

/* tried regex and failed using explode */

/* start is split point to chop out first part of page, end cuts of the last part mod to meet your needs */

$start ='Result summary';
$end = 'summaryFooter';

$matches = array();


$exploded = explode($start, $content,2);
$content = $exploded[1];

$exploded = explode($end, $content,2);
$content = $exploded[0];

/* we've got our text and some broken html here just extract text inside " " and put into array
Yes I know this is messy but it make this code easier to change to work with any shipper page */

$exploded = explode('"', $content);

/* uncomment the line below and run to list the contents of the array, you will need to view source of your status page to see the whole result. Find the array number containing your status text and change the echo line bellow substituting in your number.
Don't forget to comment it out again */

//print_r($exploded);
echo $exploded[15];



?>
/www/admin/templates/Order.Manage.Row.tpl

Find:
<input id="trackingno_%%GLOBAL_OrderId%%" name="trackingno_%%GLOBAL_OrderId%%" type="text" class="Field50" style="width:70px" value="%%GLOBAL_TrackingNo%%" /><

<input type="button" value="%%LNG_TrackSave%%" onclick="update_tracking_no('%%GLOBAL_OrderId%%', document.getElementById('trackingno_%%GLOBAL_OrderId%%').value)" class="FormButton" style="width:40px" />

Replace:
<input id="trackingno_%%GLOBAL_OrderId%%" name="trackingno_%%GLOBAL_OrderId%%" type="text" class="Field50" style="width:70px" value="%%GLOBAL_TrackingNo%%" />


<input type='button' value='Status' onclick="$('#content_%%GLOBAL_OrderId%%').load('../modules/notification/shipping/status.php?track=%%GLOBAL_TrackingNo%%')" class='FormButton' style='width:40px' /><div class="PaymentCaptured" id="content_%%GLOBAL_OrderId%%" name="content_%%GLOBAL_OrderId%%"></div>

<!--<input type="button" value="%%LNG_TrackSave%%" onclick="update_tracking_no('%%GLOBAL_OrderId%%', document.getElementById('trackingno_%%GLOBAL_OrderId%%').value)" class="FormButton" style="width:40px" />-->

If there is enough interest I'll update this to automatically set order status, run as cron and store the shipping status in the db...

martin.... might need a hand if you're up for a collab
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: DHL

Post by Martin »

Might be but events at home are rapidly overtaking my plans so it'll be a few weeks yet..
gaz
Confirmed
Confirmed
Posts: 30
Joined: Mon Jun 22, 2009 1:27 pm

Re: DHL

Post by gaz »

I know how you feel matey.

No worries, there's no huge hurry
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: DHL

Post by Martin »

gaz wrote:I know how you feel matey.
:) Oh you have no idea... trust me on this one ;)
No worries, there's no huge hurry
Just as well... I'll be honest I am seriously debating getting my Interspire shop as I want it and then spend my development time on CS-Cart (or similar) to get that tweaked as required so I can move seamlessly across in 9 months or so...
grantg
Posts: 112
Joined: Thu Oct 08, 2009 11:01 am

Re: DHL

Post by grantg »

Looks good, may integrate it at a later date.

Is there a reason why you intend leaving Interspire in 9+ months?
Cupar Garden Centre: CS-Cart Professional 2.2.5 (Converted from ISC 6.0.14 Ultimate)
Online Garden Centre: ISC 6.0.14 Professional
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: DHL

Post by Martin »

grantg wrote:Is there a reason why you intend leaving Interspire in 9+ months?
I'm sick of their attitude towards their paying customers, ignorance of customer feedback and frankly the complete lack of good common business sense or courtesy.

As to why 9 months, well that's when I anticipate having the time to actually devote to a different system and still have 3 months on my maintenance term to ease everything over gently.
gaz
Confirmed
Confirmed
Posts: 30
Joined: Mon Jun 22, 2009 1:27 pm

Re: DHL

Post by gaz »

For the record I'm with Martin on that, my contract runs out in 8 Months after which I'll be packing
Up shop and moving myself and my customers over to CS-Cart.
Customer support from Interspire has been a long a fruitless process effectively
Killing my web business as cart's I've bought for customers are full of bugs which prevent them from trading.

Interspire Shopping Cart brought me nothing except endless support requests from my customers for Interspire bugs.
Support from interspire is so slow that my customers feel I've let them down which has just resulted in me
Coding fixes and patches myself to get things in a workable state.



"For those that read the latest edition of Vis, I'd currently put their IS Support manager as approx 0.997 of Jeremy Kyle (SI)"
Post Reply