I ship to only the UK and have 4 areas, i.e. UK Mainland, Scottish Highlands etc. I have 6 types of shipping i.e. 1st class, 2nd class, 2/3 Day track etc.
What I need is to charge different rates for each area for some of the shipping types.
The expressregular shipping contrib uses country ISO codes to set the zones, I want to change this to uses the zones defined in admin/location/taxes/zones.
The zones code is:
CODE
class zones {
var $code, $title, $description, $enabled, $num_zones;
// class constructor
function zones() {
$this->code = 'zones';
$this->title = MODULE_SHIPPING_ZONES_TEXT_TITLE;
$this->description = MODULE_SHIPPING_ZONES_TEXT_DESCRIPTION;
$this->sort_order = MODULE_SHIPPING_ZONES_SORT_ORDER;
$this->icon = '';
$this->tax_class = MODULE_SHIPPING_ZONES_TAX_CLASS;
$this->enabled = ((MODULE_SHIPPING_ZONES_STATUS == 'True') ? true : false);
// CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
$this->num_zones = 3;
}
// class methods
function quote($method = '') {
global $order, $cart, $shipping_weight, $shipping_num_boxes;
if (MODULE_SHIPPING_ZONES_MODE == 'price') {
$order_total = $cart->show_total();
} else {
$order_total = $shipping_weight;
}
$dest_country = $order->delivery['country']['iso_code_2'];
$dest_zone = 0;
$error = false;
for ($i=1; $i<=$this->num_zones; $i++) {
$countries_table = constant('MODULE_SHIPPING_ZONES_COUNTRIES_' . $i);
$country_zones = split("[,]", $countries_table);
if (in_array($dest_country, $country_zones)) {
$dest_zone = $i;
break;
}// rest of the world
if ($countries_table == 'WORLD') {
$dest_zone = $i;
break;
}
// rest of the world eof
}
if ($dest_zone == 0) {
$error = true;
} else {
$shipping = -1;
$zones_cost = constant('MODULE_SHIPPING_ZONES_COST_' . $dest_zone);
$zones_table = split("[:,]" , $zones_cost);
$size = sizeof($zones_table);
for ($i=0; $i<$size; $i+=2) {
if ($order_total <= $zones_table[$i]) {
$shipping = $zones_table[$i+1];
$shipping_method = constant('MODULE_SHIPPING_ZONES_TITLE_' . $dest_zone);
if (MODULE_SHIPPING_ZONES_MODE == 'weight')
$shipping_method .= " : " . $shipping_weight . ' ' . MODULE_SHIPPING_ZONES_TEXT_UNITS;
break;
}
}
if ($shipping == -1) {
$shipping_cost = 0;
$shipping_method = MODULE_SHIPPING_ZONES_UNDEFINED_RATE;
} else {
//edited by the thecodingmonkey
if (strpos($shipping, "%") === false) {
$shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone);
} else {
$shipcost = (str_replace("%","",$shipping) / 100);
$shipping_cost = ($order_total * $shipcost) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone);
}
//edited
}
}
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_ZONES_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_ZONES_INVALID_ZONE;
if ($shipping == -1) $this->quotes['error'] = MODULE_SHIPPING_ZONES_UNDEFINED_RATE;
/* the above IF statement was added by C. Holmes chris@airchris.com October 2007.
It disables user selection of this zone shipping method if the rate is undefined.
*/
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_ZONES_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 Zones Method', 'MODULE_SHIPPING_ZONES_STATUS', 'True', 'Do you want to offer zone rate shipping?', '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_ZONES_TAX_CLASS', '0', 'Use the following tax class on the shipping 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_ZONES_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
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 ('Table Method', 'MODULE_SHIPPING_ZONES_MODE', 'weight', 'The shipping cost is based on the order total or the total weight of the items ordered.', '6', '0', 'tep_cfg_select_option(array(\'weight\', \'price\'), ', now())");
for ($i = 1; $i <= $this->num_zones; $i++) {
$default_countries = '';
if ($i == 1) {
$default_countries = 'US';
} else if ($i == 2) {
$default_countries = 'CA';
}
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 ." Countries', 'MODULE_SHIPPING_ZONES_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $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 Method Name', 'MODULE_SHIPPING_ZONES_TITLE_" . $i ."', 'UPS Ground " . $default_countries . "', 'Description of this shipping method shown during checkout. ie. UPS Ground.', '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 Table', 'MODULE_SHIPPING_ZONES_COST_" . $i ."', '3:8.50,7:10.50,99:20.00', 'Shipping rates to Zone " . $i . " destinations based on a group of maximum order weights. Example: 3:8.50,7:10.50,... Weights less than or equal to 3 would cost 8.50 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_ZONES_HANDLING_" . $i."', '0', 'Handling Fee for this shipping 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_ZONES_STATUS', 'MODULE_SHIPPING_ZONES_MODE', 'MODULE_SHIPPING_ZONES_TAX_CLASS', 'MODULE_SHIPPING_ZONES_SORT_ORDER');
for ($i=1; $i<=$this->num_zones; $i++) {
$keys[] = 'MODULE_SHIPPING_ZONES_COUNTRIES_' . $i;
$keys[] = 'MODULE_SHIPPING_ZONES_TITLE_' . $i;
$keys[] = 'MODULE_SHIPPING_ZONES_COST_' . $i;
$keys[] = 'MODULE_SHIPPING_ZONES_HANDLING_' . $i;
}
return $keys;
}
}
?>
var $code, $title, $description, $enabled, $num_zones;
// class constructor
function zones() {
$this->code = 'zones';
$this->title = MODULE_SHIPPING_ZONES_TEXT_TITLE;
$this->description = MODULE_SHIPPING_ZONES_TEXT_DESCRIPTION;
$this->sort_order = MODULE_SHIPPING_ZONES_SORT_ORDER;
$this->icon = '';
$this->tax_class = MODULE_SHIPPING_ZONES_TAX_CLASS;
$this->enabled = ((MODULE_SHIPPING_ZONES_STATUS == 'True') ? true : false);
// CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
$this->num_zones = 3;
}
// class methods
function quote($method = '') {
global $order, $cart, $shipping_weight, $shipping_num_boxes;
if (MODULE_SHIPPING_ZONES_MODE == 'price') {
$order_total = $cart->show_total();
} else {
$order_total = $shipping_weight;
}
$dest_country = $order->delivery['country']['iso_code_2'];
$dest_zone = 0;
$error = false;
for ($i=1; $i<=$this->num_zones; $i++) {
$countries_table = constant('MODULE_SHIPPING_ZONES_COUNTRIES_' . $i);
$country_zones = split("[,]", $countries_table);
if (in_array($dest_country, $country_zones)) {
$dest_zone = $i;
break;
}// rest of the world
if ($countries_table == 'WORLD') {
$dest_zone = $i;
break;
}
// rest of the world eof
}
if ($dest_zone == 0) {
$error = true;
} else {
$shipping = -1;
$zones_cost = constant('MODULE_SHIPPING_ZONES_COST_' . $dest_zone);
$zones_table = split("[:,]" , $zones_cost);
$size = sizeof($zones_table);
for ($i=0; $i<$size; $i+=2) {
if ($order_total <= $zones_table[$i]) {
$shipping = $zones_table[$i+1];
$shipping_method = constant('MODULE_SHIPPING_ZONES_TITLE_' . $dest_zone);
if (MODULE_SHIPPING_ZONES_MODE == 'weight')
$shipping_method .= " : " . $shipping_weight . ' ' . MODULE_SHIPPING_ZONES_TEXT_UNITS;
break;
}
}
if ($shipping == -1) {
$shipping_cost = 0;
$shipping_method = MODULE_SHIPPING_ZONES_UNDEFINED_RATE;
} else {
//edited by the thecodingmonkey
if (strpos($shipping, "%") === false) {
$shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone);
} else {
$shipcost = (str_replace("%","",$shipping) / 100);
$shipping_cost = ($order_total * $shipcost) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone);
}
//edited
}
}
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_ZONES_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_ZONES_INVALID_ZONE;
if ($shipping == -1) $this->quotes['error'] = MODULE_SHIPPING_ZONES_UNDEFINED_RATE;
/* the above IF statement was added by C. Holmes chris@airchris.com October 2007.
It disables user selection of this zone shipping method if the rate is undefined.
*/
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_ZONES_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 Zones Method', 'MODULE_SHIPPING_ZONES_STATUS', 'True', 'Do you want to offer zone rate shipping?', '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_ZONES_TAX_CLASS', '0', 'Use the following tax class on the shipping 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_ZONES_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
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 ('Table Method', 'MODULE_SHIPPING_ZONES_MODE', 'weight', 'The shipping cost is based on the order total or the total weight of the items ordered.', '6', '0', 'tep_cfg_select_option(array(\'weight\', \'price\'), ', now())");
for ($i = 1; $i <= $this->num_zones; $i++) {
$default_countries = '';
if ($i == 1) {
$default_countries = 'US';
} else if ($i == 2) {
$default_countries = 'CA';
}
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 ." Countries', 'MODULE_SHIPPING_ZONES_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $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 Method Name', 'MODULE_SHIPPING_ZONES_TITLE_" . $i ."', 'UPS Ground " . $default_countries . "', 'Description of this shipping method shown during checkout. ie. UPS Ground.', '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 Table', 'MODULE_SHIPPING_ZONES_COST_" . $i ."', '3:8.50,7:10.50,99:20.00', 'Shipping rates to Zone " . $i . " destinations based on a group of maximum order weights. Example: 3:8.50,7:10.50,... Weights less than or equal to 3 would cost 8.50 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_ZONES_HANDLING_" . $i."', '0', 'Handling Fee for this shipping 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_ZONES_STATUS', 'MODULE_SHIPPING_ZONES_MODE', 'MODULE_SHIPPING_ZONES_TAX_CLASS', 'MODULE_SHIPPING_ZONES_SORT_ORDER');
for ($i=1; $i<=$this->num_zones; $i++) {
$keys[] = 'MODULE_SHIPPING_ZONES_COUNTRIES_' . $i;
$keys[] = 'MODULE_SHIPPING_ZONES_TITLE_' . $i;
$keys[] = 'MODULE_SHIPPING_ZONES_COST_' . $i;
$keys[] = 'MODULE_SHIPPING_ZONES_HANDLING_' . $i;
}
return $keys;
}
}
?>
Do I just need to change the ['country']['iso_code_2'] and what do I change it too
ANy help much appreciated

