Guest Posted April 23, 2005 Share Posted April 23, 2005 (edited) Hello I have been building a site for a friend over the last few weeks, however he required a shipping module where he could set a shipping charge for a certain percent of the sub total for as many different countries as required. I searched the contributions database but couldnt find what we were looking for so decided to convert the zones rate module for our needs. However as I am only 16 my level of knowledge on php is still very low and now am stuck. So far I have managed to get rid of the shipping weight in the zones rate module which has left me with just the zones handling fee. Now i want to convert the handling fee text box to do the percentage handling fee. Any ideas how to do this, I hope you can understand what I mean. Here's the current code: <?php class zones2 { var $code, $title, $description, $enabled, $num_zones; // class constructor function zones2() { $this->code = 'zones2'; $this->title = MODULE_SHIPPING_ZONES2_TEXT_TITLE; $this->description = MODULE_SHIPPING_ZONES2_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_ZONES2_SORT_ORDER; $this->icon = ''; $this->tax_class = MODULE_SHIPPING_ZONES2_TAX_CLASS; $this->enabled = ((MODULE_SHIPPING_ZONES2_STATUS == 'True') ? true : false); // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED $this->num_zones = 5; } // class methods function quote($method = '') { global $order, $shipping_num_boxes; $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_ZONES2_COUNTRIES_' . $i); $country_zones = split("[,]", $countries_table); if (in_array($dest_country, $country_zones)) { $dest_zone = $i; break; } } if ($dest_zone == 0) { $error = true; } else { $shipping = -1; $zones_cost = $dest_zone; $zones_table = split("[:,]" , $zones_cost); $size = sizeof($zones_table); for ($i=0; $i<$size; $i+=2) { if ($shipping_weight <= $zones_table[$i]) { $shipping = $zones_table[$i+1]; $shipping_method = MODULE_SHIPPING_ZONES2_TEXT_WAY . ' ' . $dest_country; break; } } if ($shipping == -1) { $shipping_cost = 0; $shipping_method = MODULE_SHIPPING_ZONES2_UNDEFINED_RATE; } else { $shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_ZONES2_HANDLING_' . $dest_zone); } } $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_ZONES2_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_ZONES2_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_ZONES2_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_ZONES2_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_ZONES2_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_ZONES2_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())"); for ($i = 1; $i <= $this->num_zones; $i++) { $default_countries = ''; if ($i == 1) { $default_countries = 'US,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_ZONES2_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 ." Handling Fee', 'MODULE_SHIPPING_ZONES2_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_ZONES2_STATUS', 'MODULE_SHIPPING_ZONES2_TAX_CLASS', 'MODULE_SHIPPING_ZONES2_SORT_ORDER'); for ($i=1; $i<=$this->num_zones; $i++) { $keys[] = 'MODULE_SHIPPING_ZONES2_COUNTRIES_' . $i; $keys[] = 'MODULE_SHIPPING_ZONES2_HANDLING_' . $i; } return $keys; } } ?> Thanks in advance for any help. ~Ash~ Edited April 23, 2005 by Ginger_Gollum Quote Link to comment Share on other sites More sharing options...
dreamscape Posted April 23, 2005 Share Posted April 23, 2005 There are already some modules that will do what you want. This one will. You can set up as many zones as you want, as many tables as you want, and you can make the shipping a percentage if you want http://www.oscommerce.com/community/contributions,2571 Quote The only thing necessary for evil to flourish is for good men to do nothing - Edmund Burke Link to comment Share on other sites More sharing options...
Guest Posted April 23, 2005 Share Posted April 23, 2005 Oh great Thanks! 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.