Guest Posted January 6, 2005 Share Posted January 6, 2005 Hi all, I am using Region Based Rates and this module is working fine. I have two rates for each country. One is Air Shipment Charge and another one is Surface Shipment Charge. Using Region Based Rates module i am able to do any one of these two options. but i dont know how to do the second charge. Is there any option to duplicate this Module. or is there any other option available? Please Help Thanks in advance venkat Quote Link to comment Share on other sites More sharing options...
Jeremy at oddly enough Posted February 21, 2005 Share Posted February 21, 2005 Yes, I've done this, it works well! You need to simply modify the original download a bit to duplicate its function with a different name, and change the names of the tables it looks for. It is installed once unmodded, and once after you've done a find and replace to change from regions to air regions this way, with ground and air functioning the same manner. Here is the code for both the regions.php, and airregions.php to show you the minor changes you'll need to make: <?php /* $Id: regions.php, v 1.0 2002/12/15 14:29:56 Jorge Exp $ Based upon zones.php by wilt, written for: osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2002 osCommerce Released under the GNU General Public License ----------------------------------------------------------------------------- REGIONS - Rates Based on State or Regions (group of States) module for osC 2.2-CVS (new checkout) This module allows you create shipping regions by dividing states of the USA (or other country) in different groups. Each group will then have it's own shipping price which you can based on price or weight. This module is perfect when for those of you need to charge different when shipping to different parts of the country. Features 1..Regions can be composed of US States or of any other country 2..Order weight or price can be used to calculate shipping price. 3..Any number of regions 4..Handling fee can be added. Jorge Set the number of regions you need with $this->regions = xx; Please note that any country / state that is not in one of the groups will not be able to checkout if this the only shipping you provide. However it will display a nice message saying so. Written by Jorge ([email protected]) */ class regions { var $code, $title, $description, $enabled, $regions; // class constructor function regions() { $this->code = 'regions'; $this->title = MODULE_SHIPPING_REGIONS_TEXT_TITLE; $this->description = MODULE_SHIPPING_REGIONS_TEXT_DESCRIPTION; $this->icon = ''; $this->enabled = MODULE_SHIPPING_REGIONS_STATUS; // CUSTOMIZE THIS SETTING FOR THE NUMBER OF States NEEDED $this->regions = 11; } // class methods function quote($method = '') { global $order, $shipping_weight, $cart, $total_count; if (MODULE_SHIPPING_REGIONS_MODE == 'price') { $order_total_price = $cart->show_total(); } if (MODULE_SHIPPING_REGIONS_MODE == 'weight') { $order_total_price = $shipping_weight; } if (MODULE_SHIPPING_REGIONS_MODE == 'per_item') { $order_total_price = $total_count; } $dest_state = $order->delivery['state']; $dest_country = $order->delivery['country']['title']; $dest_region = 0; $error = false; for ($i=1; $i<=$this->regions; $i++) { $regions_table = constant('MODULE_SHIPPING_REGIONS' . $i); $country_states_or_countries = split("[,]", $regions_table); if (in_array($dest_state, $country_states_or_countries)) { $dest_region = $i; break; } } if ($dest_region == 0) { for ($i=1; $i<=$this->regions; $i++) { $regions_table = constant('MODULE_SHIPPING_REGIONS' . $i); $country_states_or_countries = split("[,]", $regions_table); if (in_array($dest_country, $country_states_or_countries)) { $dest_region = $i; break; } } } if ($dest_region == 0) { $error = true; } else { $shipping = -1; $region_cost = constant('MODULE_SHIPPING_REGIONS_COST' . $i); $regions_table = split("[:,]" , $region_cost); if ((MODULE_SHIPPING_REGIONS_MODE == 'price') || (MODULE_SHIPPING_REGIONS_MODE == 'weight')) { for ($i=0; $i<sizeof($regions_table); $i+=2) { if ($order_total_price <= $regions_table[$i]) { $shipping = $regions_table[$i+1]; $shipping_method = MODULE_SHIPPING_REGIONS_TEXT_WAY . ' ' . "$dest_state, $dest_country" . ' ' . MODULE_SHIPPING_REGIONS_TEXT_UNITS; break; } } } if (MODULE_SHIPPING_REGIONS_MODE == 'per_item') { $shipping = $regions_table[1] * $order_total_price; $shipping_method = MODULE_SHIPPING_REGIONS_ITEM . ' ' . $total_count . ' ' . MODULE_SHIPPING_REGIONS_ITEMS . ' ' . "$dest_state, $dest_country" . ' ' . MODULE_SHIPPING_REGIONS_TEXT_UNITS; } if ($shipping == -1) { $shipping_cost = 0; $shipping_method = MODULE_SHIPPING_REGIONS_UNDEFINED_RATE; } else { $shipping_cost = ($shipping + MODULE_SHIPPING_REGIONS_HANDLING + SHIPPING_HANDLING); } } $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_REGIONS_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => $shipping_method, 'cost' => $shipping_cost))); if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title); if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_REGIONS_INVALID_ZONE; 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_REGIONS_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, date_added) VALUES ('Enable US Regions Method', 'MODULE_SHIPPING_REGIONS_STATUS', '1', 'Do you want to offer Regions rate shipping?', '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 ('Handling Fee', 'MODULE_SHIPPING_REGIONS_HANDLING', '0', 'Handling Fee for this shipping method', '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 ('Mode', 'MODULE_SHIPPING_REGIONS_MODE', 'weight', 'Is the shipping table based on total Weight or Total amount of order.', '6', '0', 'tep_cfg_select_option(array(\'weight\', \'price\', \'per_item\'), ', now())"); for ($i = 1; $i <= $this->regions; $i++) { $default_countries = ''; if ($i == 1) { $default_states_or_countries = 'California'; $default_prices = '30:8.95,75:10.95,150:16.95,400:21.95,10000:25.95'; } if ($i == 2) { $default_states_or_countries = 'Alabama,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,District of Columbia,Florida,Georgia,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,M aine,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana'; $default_prices = '30:10.95,75:12.95,150:18.95,400:23.95,10000:27.95'; } if ($i == 3) { $default_states_or_countries = 'Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming'; $default_prices = '30:10.95,75:12.95,150:18.95,400:23.95,10000:27.95'; } tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Region " . $i ." States/Countries', 'MODULE_SHIPPING_REGIONS" . $i ."', '" . $default_states_or_countries . "', 'Comma separated list of States and/or Countries', '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 ('Region " . $i ." Shipping Table', 'MODULE_SHIPPING_REGIONS_COST" . $i ."', '" . $default_prices . "' , 'Example: 3:8.50,7:10.50.....(weight/price)<b>:</b>(shipping cost)', '6', '0', now())"); } } function remove() { $keys = ''; $keys_array = $this->keys(); for ($i=0; $i<sizeof($keys_array); $i++) { $keys .= "'" . $keys_array[$i] . "',"; } $keys = substr($keys, 0, -1); tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")"); } function keys() { $keys = array('MODULE_SHIPPING_REGIONS_STATUS', 'MODULE_SHIPPING_REGIONS_HANDLING', 'MODULE_SHIPPING_REGIONS_MODE'); for ($i=1; $i<=$this->regions; $i++) { $keys[] = 'MODULE_SHIPPING_REGIONS' . $i; $keys[] = 'MODULE_SHIPPING_REGIONS_COST' . $i; } return $keys; } } ?> <?php /* $Id: airregions.php, v 1.0 2002/12/15 14:29:56 Jorge Exp $ Based upon zones.php by wilt, written for: osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2002 osCommerce Released under the GNU General Public License ----------------------------------------------------------------------------- REGIONS - Rates Based on State or Regions (group of States) module for osC 2.2-CVS (new checkout) This module allows you create shipping airregions by dividing states of the USA (or other country) in different groups. Each group will then have it's own shipping price which you can based on price or weight. This module is perfect when for those of you need to charge different when shipping to different parts of the country. Features 1..Regions can be composed of US States or of any other country 2..Order weight or price can be used to calculate shipping price. 3..Any number of airregions 4..Handling fee can be added. Jorge Set the number of airregions you need with $this->airregions = xx; Please note that any country / state that is not in one of the groups will not be able to checkout if this the only shipping you provide. However it will display a nice message saying so. Written by Jorge ([email protected]) */ class airregions { var $code, $title, $description, $enabled, $airregions; // class constructor function airregions() { $this->code = 'airregions'; $this->title = MODULE_SHIPPING_AIRREGIONS_TEXT_TITLE; $this->description = MODULE_SHIPPING_AIRREGIONS_TEXT_DESCRIPTION; $this->icon = ''; $this->enabled = MODULE_SHIPPING_AIRREGIONS_STATUS; // CUSTOMIZE THIS SETTING FOR THE NUMBER OF States NEEDED $this->airregions = 11; } // class methods function quote($method = '') { global $order, $shipping_weight, $cart, $total_count; if (MODULE_SHIPPING_AIRREGIONS_MODE == 'price') { $order_total_price = $cart->show_total(); } if (MODULE_SHIPPING_AIRREGIONS_MODE == 'weight') { $order_total_price = $shipping_weight; } if (MODULE_SHIPPING_AIRREGIONS_MODE == 'per_item') { $order_total_price = $total_count; } $dest_state = $order->delivery['state']; $dest_country = $order->delivery['country']['title']; $dest_region = 0; $error = false; for ($i=1; $i<=$this->airregions; $i++) { $airregions_table = constant('MODULE_SHIPPING_AIRREGIONS' . $i); $country_states_or_countries = split("[,]", $airregions_table); if (in_array($dest_state, $country_states_or_countries)) { $dest_region = $i; break; } } if ($dest_region == 0) { for ($i=1; $i<=$this->airregions; $i++) { $airregions_table = constant('MODULE_SHIPPING_AIRREGIONS' . $i); $country_states_or_countries = split("[,]", $airregions_table); if (in_array($dest_country, $country_states_or_countries)) { $dest_region = $i; break; } } } if ($dest_region == 0) { $error = true; } else { $shipping = -1; $region_cost = constant('MODULE_SHIPPING_AIRREGIONS_COST' . $i); $airregions_table = split("[:,]" , $region_cost); if ((MODULE_SHIPPING_AIRREGIONS_MODE == 'price') || (MODULE_SHIPPING_AIRREGIONS_MODE == 'weight')) { for ($i=0; $i<sizeof($airregions_table); $i+=2) { if ($order_total_price <= $airregions_table[$i]) { $shipping = $airregions_table[$i+1]; $shipping_method = MODULE_SHIPPING_AIRREGIONS_TEXT_WAY . ' ' . "$dest_state, $dest_country" . ' ' . MODULE_SHIPPING_AIRREGIONS_TEXT_UNITS; break; } } } if (MODULE_SHIPPING_AIRREGIONS_MODE == 'per_item') { $shipping = $airregions_table[1] * $order_total_price; $shipping_method = MODULE_SHIPPING_AIRREGIONS_ITEM . ' ' . $total_count . ' ' . MODULE_SHIPPING_AIRREGIONS_ITEMS . ' ' . "$dest_state, $dest_country" . ' ' . MODULE_SHIPPING_AIRREGIONS_TEXT_UNITS; } if ($shipping == -1) { $shipping_cost = 0; $shipping_method = MODULE_SHIPPING_AIRREGIONS_UNDEFINED_RATE; } else { $shipping_cost = ($shipping + MODULE_SHIPPING_AIRREGIONS_HANDLING + SHIPPING_HANDLING); } } $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_AIRREGIONS_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => $shipping_method, 'cost' => $shipping_cost))); if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title); if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_AIRREGIONS_INVALID_ZONE; 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_AIRREGIONS_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, date_added) VALUES ('Enable US Regions Method', 'MODULE_SHIPPING_AIRREGIONS_STATUS', '1', 'Do you want to offer Regions rate shipping?', '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 ('Handling Fee', 'MODULE_SHIPPING_AIRREGIONS_HANDLING', '0', 'Handling Fee for this shipping method', '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 ('Mode', 'MODULE_SHIPPING_AIRREGIONS_MODE', 'weight', 'Is the shipping table based on total Weight or Total amount of order.', '6', '0', 'tep_cfg_select_option(array(\'weight\', \'price\', \'per_item\'), ', now())"); for ($i = 1; $i <= $this->airregions; $i++) { $default_countries = ''; if ($i == 1) { $default_states_or_countries = 'California'; $default_prices = '30:8.95,75:10.95,150:16.95,400:21.95,10000:25.95'; } if ($i == 2) { $default_states_or_countries = 'Alabama,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,District of Columbia,Florida,Georgia,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,M aine,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana'; $default_prices = '30:10.95,75:12.95,150:18.95,400:23.95,10000:27.95'; } if ($i == 3) { $default_states_or_countries = 'Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming'; $default_prices = '30:10.95,75:12.95,150:18.95,400:23.95,10000:27.95'; } tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Region " . $i ." States/Countries', 'MODULE_SHIPPING_AIRREGIONS" . $i ."', '" . $default_states_or_countries . "', 'Comma separated list of States and/or Countries', '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 ('Region " . $i ." Shipping Table', 'MODULE_SHIPPING_AIRREGIONS_COST" . $i ."', '" . $default_prices . "' , 'Example: 3:8.50,7:10.50.....(weight/price)<b>:</b>(shipping cost)', '6', '0', now())"); } } function remove() { $keys = ''; $keys_array = $this->keys(); for ($i=0; $i<sizeof($keys_array); $i++) { $keys .= "'" . $keys_array[$i] . "',"; } $keys = substr($keys, 0, -1); tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")"); } function keys() { $keys = array('MODULE_SHIPPING_AIRREGIONS_STATUS', 'MODULE_SHIPPING_AIRREGIONS_HANDLING', 'MODULE_SHIPPING_AIRREGIONS_MODE'); for ($i=1; $i<=$this->airregions; $i++) { $keys[] = 'MODULE_SHIPPING_AIRREGIONS' . $i; $keys[] = 'MODULE_SHIPPING_AIRREGIONS_COST' . $i; } return $keys; } } ?> Hope this helps, Jeremy Quote Link to comment Share on other sites More sharing options...
Jeremy at oddly enough Posted February 22, 2005 Share Posted February 22, 2005 This post by terry describes the process used to duplicate a shipping module. http://www.oscommerce.com/forums/index.php?sho...ndpost&p=553644 This is just the sort of process I followed to make the two pages posted above. Jeremy Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.