Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Quote for osc coding job - DEVELOPER REQUIRED


Guest

Recommended Posts

Hello,

 

I need a postcode, 3 zone shipping, implementing...

 

(This is for the uk fastway courier company)

 

There will be 3 Zones, postcode driven, i already have the db setup with all of the postcode & zones in.

 

When on the shipping page, depending on what postcode the customer has, will determine what zone prices are displayed.

 

On top of that there's free delivery over a certain amount.

 

Zone 1 - Free shipping for all orders over £25, otherwise £4 flat rate

Zone 2 - Free shipping for all orders over £45, otherwise £10.95 flat rate

Zone 3 - Free shipping for all orders over £45, otherwise £11.95 flat rate

 

 

So if zone 1 catered for the NE1 postcode, and i was from NE1, and i had a £10 order in my cart, it would display a flat rate of £4

If i had a NE1 postcode and had a £26 order in my cart, it would display FREE shipping

 

etc etc

 

Sounds easy in theory, however i have been pulling my hair out for weeks trying to get this to work. I nearly did it myself aswell, however, the damn script wouldnt allow me to click proceed and was stuck in a loop. Dont you just hate it when that happens.

 

So basically all files/db's are there, just needs someone with more experienc to look at it and say "you've left an extra single quote in line345 and that's preventing it from proceeding", or something like that anyway....

 

Thanks in advance

Dave.

Link to comment
Share on other sites

Hello,

 

I need a postcode, 3 zone shipping, implementing...

 

(This is for the uk fastway courier company)

 

There will be 3 Zones, postcode driven, i already have the db setup with all of the postcode & zones in.

 

When on the shipping page, depending on what postcode the customer has, will determine what zone prices are displayed.

 

On top of that there's free delivery over a certain amount.

 

Zone 1 - Free shipping for all orders over £25, otherwise £4 flat rate

Zone 2 - Free shipping for all orders over £45, otherwise £10.95 flat rate

Zone 3 - Free shipping for all orders over £45, otherwise £11.95 flat rate

So if zone 1 catered for the NE1 postcode, and i was from NE1, and i had a £10 order in my cart, it would display a flat rate of £4

If i had a NE1 postcode and had a £26 order in my cart, it would display FREE shipping

 

etc etc

 

Sounds easy in theory, however i have been pulling my hair out for weeks trying to get this to work. I nearly did it myself aswell, however, the damn script wouldnt allow me to click proceed and was stuck in a loop. Dont you just hate it when that happens.

 

So basically all files/db's are there, just needs someone with more experienc to look at it and say "you've left an extra single quote in line345 and that's preventing it from proceeding", or something like that anyway....

 

Thanks in advance

Dave.

Why not post the script and see if anyone can help?

Link to comment
Share on other sites

MVS will do what you want it to do with some tweaking

"I must admit that I personally measure success in terms of the contributions an individual makes to her or his fellow human beings."

---Margaret Mead---

 

"The answer is never the answer. What's really interesting is the mystery. If you seek the mystery instead of the answer, you'll always be seeking. I've never seen anybody really find the answer -- they think they have, so they stop thinking. But the job is to seek mystery, evoke mystery, plant a garden in which strange plants grow and mysteries bloom. The need for mystery is greater than the need for an answer.

--Ken Kesey"

Link to comment
Share on other sites

Thanks for the suggestion of posting the script..... and the suggestion of MVS, i will look at it later, however i seem to have come so far with this script, so seems a waste to not try and get it working....

 

For my terrible attempt at trying to do this, i created 6 files,

 

Zone1 - Under

Zone1 - Over

Zone2 - Under

Zone2 - Over

Zone3 - Under

 

I know what your thinking, why create 6 scripts when 1 could have done it all, well, unfortunatly im not very good at php so i tried to improvise. That'll teach me eh!

 

Anyway, The script below is taken from ZONE 1 UNDER.php, as you have probably guessed, it executes if the customer has a postcode in zone 1 and if the order amount is under £25.

 

I dont even know what half of the code does, but i added some code that, first of all, if the order is less than £25 doesnt display script on the shipping page, then it splits the postcode and checks the db for what zone the postcode is in (from NE1 1AA, to NE1). It then works out the shipping price, which is £4 for zone 1 and displays that on the shipping page. Thats it in a nutshell, so the problem is, it displays and appears to work ok on the shipping page, but when you select the radio button and click proceed, it just refreshs back to the shipping page.

 

  class zone1_under {
var $code, $title, $description, $enabled, $num_zones;

// class constructor
function zone1_under() {

  $this->code = 'zone1_under';
  $this->title = MODULE_SHIPPING_ZONE1_UNDER_TEXT_TITLE;
  $this->description = MODULE_SHIPPING_ZONE1_UNDER_TEXT_DESCRIPTION;
  $this->sort_order = MODULE_SHIPPING_ZONE1_UNDER_SORT_ORDER;
  $this->icon = DIR_WS_ICONS . 'courier.gif';
  $this->tax_class = MODULE_SHIPPING_ZONE1_UNDER_TAX_CLASS;
  $this->enabled = ((MODULE_SHIPPING_ZONE1_UNDER_STATUS == 'True') ? true : false);


  // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
  $this->num_zones = 1;
}



// class methods
function quote($method = '') {
  global $order, $shipping_weight, $shipping_num_boxes;

$shipping_num_boxes = "1";

// if order less than 25 pounds dont display
if($order->info['subtotal'] > 25) {
 $this->quotes['error'] = "";
 return $this->quotes;
}

####################################
if($order->delivery['postcode']==''){
 // Something is wrong, no matching area code
 $this->quotes['error'] = "No Post Code available for the customer data";
 return $this->quotes;
}


//First split the destination postcode and check the db for matching delivery zone
$postcode = $order->delivery['postcode'];
$postcode = str_replace(' ', "", $postcode);
$postcode = str_replace('-', "", $postcode);
$postcode = str_replace('/', "", $postcode);
$t_postcode = substr($postcode, 0, 5);
$sql = "SELECT * FROM toll_zones WHERE t_postcode = '".$t_postcode."'";
$qResult = tep_db_query($sql); // run the query


if(mysql_num_rows($qResult) < 1)
{
$t_postcode = substr($postcode, 0, 4);
$sql = "SELECT * FROM toll_zones WHERE t_postcode = '".$t_postcode."'";
$qResult = tep_db_query($sql); // run the query
$exec = true
}

if(mysql_num_rows($qResult) < 1 && $exec = false)
{
$t_postcode = substr($postcode, 0, 3);
$sql = "SELECT * FROM toll_zones WHERE t_postcode = '".$t_postcode."'";
$qResult = tep_db_query($sql); // run the query
}


$rec = tep_db_fetch_array($qResult); // get the first row of the result
$dest_zipcode = $rec['t_zone'];

//checks to see if there is a blank areazone entry and returns error message if not
  if ($dest_zipcode == '' ){
 $this->quotes['error'] = "Please call us to organise delivery 0777******";
	  return $this->quotes;
  }

####################################

$dest_zone = 1;


$shipping = -1;
$carriercode_cost = constant('MODULE_SHIPPING_ZONE1_UNDER_COST_' . $dest_zone);

$carriercode_table = split("[:,]" , $carriercode_cost);
$size = sizeof($carriercode_table);
for ($i=0; $i<$size; $i+=2) {
  if ($shipping_weight <= $carriercode_table[$i]) {
	$shipping = $carriercode_table[$i+1];
	$shipping_method = MODULE_SHIPPING_ZONE1_UNDER_TEXT_WAY . ' ' . $t_postcode;
	break;
  }
}

if ($shipping == -1) {
  $shipping_cost = 0;
  $shipping_method = MODULE_SHIPPING_ZONE1_UNDER_UNDEFINED_RATE;
} else {
  $shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_ZONE1_UNDER_HANDLING_' . $dest_zone);
}


  $this->quotes = array('id' => $this->code,
						'module' => MODULE_SHIPPING_ZONE1_UNDER_TEXT_TITLE,
						'methods' => array(array('id' => $this->code,
												 'title' => $shipping_method,
												 'cost' => $shipping_cost)));

  if ($this->tax_class > 0) {
	$this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  }

  if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);

  if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_ZONE1_UNDER_INVALID_CODE;

  return $this->quotes;
}

####################################

function check() {
  if (!isset($this->_check)) {
	$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_ZONE1_UNDER_STATUS'");
	$this->_check = tep_db_num_rows($check_query);
  }
  return $this->_check;
}


function install() {
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable UK carrier zone delivery', 'MODULE_SHIPPING_ZONE1_UNDER_STATUS', 'True', 'Offer UK carrier shipping by carrier zone?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_ZONE1_UNDER_TAX_CLASS', '0', 'Use the following tax class on the shipping/delivery fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_ZONE1_UNDER_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
  for ($i = 1; $i <= $this->num_zones; $i++) {
	$default_zipcodes = '';
	if ($i == 1) {
	  $default_carriercodes = '0,10,14,18,21';
	  $default_dlvtable = '10:9.50,11:10.00,12:10.50,13:11.00,14:11.50,15:12.00,16:12.50,17:13.00,18:13.50,19:14.00,20:200.00';
	} else if ($i == 2) {
	  $default_carriercodes = '1';
	  $default_dlvtable = '10:24.90,11:25.90,12:26.90,13:27.90,14:28.90,15:29.90,99:200.00';
	} else if ($i == 3) {
	  $default_carriercodes = '2';
	  $default_dlvtable = '10:27.00,11:28.00,12:29.00,13:30.00,14:31.00,15:32.00,16:33.00,17:34.00,99:200.00';
	} else if ($i == 4) {
	  $default_carriercodes = '17,20';
	  $default_dlvtable = '10:10.00,11:10.50,12:11.00,13:11.50,14:12.00,15:12.50,16:13.00,17:13.50,18:14.00,99:200.00';
	} else if ($i == 5) {
	  $default_carriercodes = '5';
	  $default_dlvtable = '5:40.00,6:43.00,7:46.00,8:49.00,9:52.00,10:55.00,99:500.00';
	} else if ($i == 6) {
	  $default_carriercodes = '6';
	  $default_dlvtable = '10:25.00,11:25.50,12:26.00,13:26.50,14:27.00,15:27.50,16:28.00,17:28.50,18:29.00,99:200.00';
	} else if ($i == 7) {
	  $default_carriercodes = '8';
	  $default_dlvtable = '20:40.50,21:41.20,22:41.90,23:42.60,99:200.00';
	} else if ($i == 8) {
	  $default_carriercodes = '9';
	  $default_dlvtable = '5:41.50,6:44.50,7:47.50,8:50.50,9:53.50,10:56.50,99:500.00';
	} else if ($i == 9) {
	  $default_carriercodes = '12,15';
	  $default_dlvtable = '20:10.00,21:10.50,22:11.00,23:11.50,24:12.00,25:12.50,26:13.00,27:13.50,28:14.00,99:200.00';
	} else if ($i == 10) {
	  $default_carriercodes = '19';
	  $default_dlvtable = '5:44.50,6:48.50,7:52.00,8:56.00,9:60.00,10:64.00,99:500.00';
	} else if ($i == 11) {
	  $default_carriercodes = '13';
	  $default_dlvtable = '10:19,11:19.50,12:20.00,13:20.50,14:21.00,15:21.50,16:22.00,17:22.50,18:23.00,19:23.50,20:200.00';
	}
	tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Delivery zones(s)', 'MODULE_SHIPPING_ZONE1_UNDER_CODES_" . $i ."', '" . $default_carriercodes . "', 'Comma separated list of carrier delivery zones with this tariff " . $i . ".', '6', '0', now())");
	tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Shipping/Delivery Fee Table', 'MODULE_SHIPPING_ZONE1_UNDER_COST_" . $i ."', '" . $default_dlvtable . "', 'Shipping rates to Zone " . $i . " destinations based on a group of maximum order weights. Example: 4:5,8:7,... weights less than or equal to 4 would cost $5 for Zone " . $i . " destinations.', '6', '0', now())");
	tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Handling Fee', 'MODULE_SHIPPING_ZONE1_UNDER_HANDLING_" . $i."', '0', 'Handling Fee for this delivery zone', '6', '0', now())");
  }
}

function remove() {
  tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}

function keys() {
  $keys = array('MODULE_SHIPPING_ZONE1_UNDER_STATUS', 'MODULE_SHIPPING_ZONE1_UNDER_TAX_CLASS', 'MODULE_SHIPPING_ZONE1_UNDER_SORT_ORDER');

  for ($i=1; $i<=$this->num_zones; $i++) {
	$keys[] = 'MODULE_SHIPPING_ZONE1_UNDER_CODES_' . $i;
	$keys[] = 'MODULE_SHIPPING_ZONE1_UNDER_COST_' . $i;
	$keys[] = 'MODULE_SHIPPING_ZONE1_UNDER_HANDLING_' . $i;
  }

  return $keys;
}
 }

Link to comment
Share on other sites

This is my perfect example as to why i'd rather pay someone to help fix this, as generally no one reply's to these support requests, unless money offers are made. :(

Link to comment
Share on other sites

I took a slightly different route to the same end by adding another included file to do the conditionals (13 different postal options) based on weight/length (<or>610mm)/destination. I'm sure it could be modified fairly easily to work on Post Code instead of Country Code. I posted the included file in another thread (http://www.oscommerce.com/forums/index.php?s=&...t&p=1148553) relating to PHP5 issues. You can take a look at it there.

 

There is some modification required to other files and new db TABLE but it's quite straight forward. Once I get this PHP5 issue resolved, I hope to put it up as a contribution for others that need an array of shipping options.

* * * * * * * * * * * * * * * * * * * * *

Porpoises are most happy when wet!

\ _ \ _ \ _ \ _ \ _ \ _ \ _ \ _ \ _ \ _ \ _ \ _

Link to comment
Share on other sites

Thanks for your reply.

 

However i managed to fix it in the end.

 

 

Can you see where i've called the shipping module zone1_under well, you cant use underscores in those names!

 

Otherwise line 108 in checkout_shipping.php breaks it.

 

list($module, $method) = explode('_', $shipping);

 

 

So lesson for anyone out there trying to do the same as me. Dont use underscores in those names.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...