Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

UK Postcode Shipping Rates


adz1976

Recommended Posts

Hi OSC Guys

 

I am running a UK Postcode module which works out a shipping price from the weight & postcode.

 

This is done though a file called post_code_del_price.csv

 

The module works as it should but I need to amend it so it only picks up 1 service instead of 2.

The 2 services are (cheapest / quickest) economy / next day

 

Instead of it working out particular services I just want the programming to work out 1 service shipping rate and for that service to pick up every column on the shipping unlike now where it chops and changes.

 

For example in my now amended .CSV FIle:

If I chose an item for 39kg it is picking up the 300kg pallet service at £19.99 when it should be picking up the UPS Service at £10.99 but it is working out cheapest and quickest from the original file.

 

I hope ive explained this correctly & hope someone out there is able to amend the programming. It doesnt look like its difficult & I understand what needs to be one but I just dont get which parts of the programming to change to get it to just pick up all columns in the .csv file to work as 1 service.

 

Ive attached 2 pics to let you see the .CSV Files. One is the original and the other is which ive amended.

 

Heres the file:

 

<?php

/* getrate.php

by Tony Bell August 2008

This function is passed a UK post code, a weight and a service type

and will look up a shipment cost based upon these inputs.

Service type = 0 for quick/next day, =1 for economy

The lookup table is located in post_code_del_price.csv which can

be edited to suit.

The function returns an array with [0] - the cost, [1] - the selected method or

a Null if the postcode cannot be found or no service is available.

The csv file contains 9 columns{

1- First part of the postcode

2- The district this is in

3- Rate for full pallet next day

4- Rate for full pallet economy

5- Rate for half pallet next day

6- Rate for helf pallet economy

7- Rate for quarter pallet next day

8- Rate for quarter pallet economy

9- Standard Box Rate

The first row contains the shipping description which is passed back

The second row contains the weight threshold levels relevant for that service

If no service is available for a particular postcode 'NA' must be entered

*/

function getrate($gr_postcode,$weight,$service_type=0) {

$gr_postcode = strtoupper($gr_postcode);

//makes it upper case

$gr_postcode = strtok($gr_postcode,' ');

//splits the string where the space is

$filename = DIR_WS_FUNCTIONS . "post_code_del_price.csv";

$handle = fopen($filename,"r");

$quickest = 9999;

$quickref = 0;

$cheapest = 9999;

$cheapref = 0;

$line = 0;

while ($content = fgetcsv($handle, 1000, ",")) {

$line++;

 

if ($line == 1){

$gr_method = $content;

//if it's the first line, load in the headers

}

// echo $line . ":" . $content[0] . ":" . $content[1] . ":" .$content[2] . ":" .$content[3] . ":" .$content[4] . ":" .$content[5] . ":" .$content[6] . ":" .$content[7] . ":" .$content[8] . ":" .$content[9] . "<br>";

if ($line == 2){

//the second line holds the weight threshold limits

$lowthreshold = $content[8];

$qpcutoff = $content[6];

$hpcutoff = $content[4];

$fpcutoff = $content[2];

}

 

if($content[0] == $gr_postcode){

//postcode match

//find quickest lowest cost route

 

if ($weight <= $lowthreshold){

 

if ($content[8] != "NA") {

$quickest = $content[8];

$quickref = 8;

}

}

if ($weight <= $qpcutoff){

 

if ($content[6]!="NA" && $content[6] < $quickest){

$quickest = $content[6];

$quickref = 6;

}

}

if ($weight <= $hpcutoff){

 

if ($content[4] != "NA" && $content[4] < $quickest){

$quickest = $content[4];

$quickref = 4;

}

}

if ($weight <= $fpcutoff){

 

if ($content[2] != "NA" && $content[2] < $quickest){

$quickest = $content[2];

$quickref = 2;

}

}

//find cheapest cost route

if ($weight <= $lowthreshold){

 

if ($content[8] != "NA") {

$cheapest = $content[8];

$cheapref = 8;

}

}

if ($weight <= $qpcutoff){

 

if ($content[7]!="NA" && $content[7] < $cheapest){

$cheapest = $content[7];

$cheapref = 7;

}

}

if ($weight <= $hpcutoff){

 

if ($content[5] != "NA" && $content[5] < $cheapest){

$cheapest = $content[5];

$cheapref = 5;

}

}

if ($weight <= $fpcutoff){

 

if ($content[3] != "NA" && $content[3] < $cheapest){

$cheapest = $content[3];

$cheapref = 3;

}

}

break;

}

}

 

if (($quickest == 9999 && $cheapest == 9999) || $weight == 0 || $gr_postcode == ''){

//There is no service

return null;

} else {

 

if ($quickest <9999 && $quickest <= $cheapest){

//There is no cheap service, or cheap is a more expensive service

$cheapest = $quickest;

$cheapref = $quickref;

}

if ($quickest == 9999 && $cheapest < 9999){

//There is no quick service, so make the same as cheap.

$quickest = $cheapest;

$quickref = $cheapref;

}

if ($service_type == 1) {

//quick service

return array($quickest,$gr_method[$quickref]);

} elseif ($service_type == 0) {

//low cost service

return array($cheapest,$gr_method[$cheapref]);

} else {

return null;

}

}

return null;

fclose($handle);

}

?>

 

Many thanks & Hope you can help

 

Adam :)

post-146986-0-91893000-1348575619_thumb.gif

post-146986-0-18567900-1348575626_thumb.gif

Link to comment
Share on other sites

Actually, it only returns the quickest.

 

As it says in the documentation

 

4) If the want the cheapest option to be found change
$ratebypostcode=getrate($order->delivery['postcode'],$shipping_weight,0);
to
$ratebypostcode=getrate($order->delivery['postcode'],$shipping_weight,1);

 

Either you need to increase the number of bands and add extra coding or strip out the coding for cheapest and amend use all the "extra" bands.

 

Not something that can be explained in detail in a post.

 

HTH

 

G

Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...