Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Duplicating Zones.php


MrNickRegan

Recommended Posts

Evening All,

 

I hope that maybe someone can point me in the right direction on this. I cloned Zones.php to Zones1.php to try and create two different types of shipping (standard & Signed for), the cloned module installs okay however has no zones to enter my criteria ... any advice where I have gone wrong, I have pasted my code below.

 

*/
 
  class zones1 {
    var $code, $title, $description, $enabled, $num_zones1;
 
// class constructor
    function zones1() {
      $this->code = 'zones1';
      $this->title = MODULE_SHIPPING_ZONES1_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_ZONES1_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_SHIPPING_ZONES1_SORT_ORDER;
      $this->icon = '';
      $this->tax_class = MODULE_SHIPPING_ZONES1_TAX_CLASS;
      $this->enabled = ((MODULE_SHIPPING_ZONES1_STATUS == 'True') ? true : false);
 
      // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
      $this->num_zones1 = 3;
    }
 
// class methods
    function quote($method = '') {
      global $order, $shipping_weight, $shipping_num_boxes;
 
      $dest_country = $order->delivery['country']['iso_code_3'];
      $dest_zone = 0;
      $error = false;
 
      for ($i=1; $i<=$this->num_zones1; $i++) {
        $countries_table = constant('MODULE_SHIPPING_ZONES1_COUNTRIES_' . $i);
        $country_zones1 = preg_split("/[,]/", $countries_table);
        if (in_array($dest_country, $country_zones1)) {
          $dest_zone = $i;
          break;
        }
      }
 
      if ($dest_zone == 0) {
        $error = true;
      } else {
        $shipping = -1;
        $zones1_cost = constant('MODULE_SHIPPING_ZONES1_COST_' . $dest_zone);
 
        $zones1_table = preg_split("/[:,]/" , $zones1_cost);
        $size = sizeof($zones1_table);
        for ($i=0; $i<$size; $i+=2) {
          if ($shipping_weight <= $zones1_table[$i]) {
            $shipping = $zones1_table[$i+1];
            $shipping_method = MODULE_SHIPPING_ZONES1_TEXT_WAY . ' ' . $dest_country . ' : ' . $shipping_weight . ' ' . MODULE_SHIPPING_ZONES1_TEXT_UNITS;
            break;
          }
        }
 
        if ($shipping == -1) {
          $shipping_cost = 0;
          $shipping_method = MODULE_SHIPPING_ZONES1_UNDEFINED_RATE;
        } else {
          $shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_ZONES1_HANDLING_' . $dest_zone);
        }
      }
 
      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_ZONES1_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_ZONES1_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_ZONES1_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 Zones1 Method', 'MODULE_SHIPPING_ZONES1_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_ZONES1_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_ZONES1_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
      for ($i = 1; $i <= $this->num_zones1; $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_ZONES1_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 Table', 'MODULE_SHIPPING_ZONES1_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_ZONES1_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_ZONES1_STATUS', 'MODULE_SHIPPING_ZONES1_TAX_CLASS', 'MODULE_SHIPPING_ZONES1_SORT_ORDER');
 
      for ($i=1; $i<=$this->num_zones; $i++) {
        $keys[] = 'MODULE_SHIPPING_ZONES1_COUNTRIES_' . $i;
        $keys[] = 'MODULE_SHIPPING_ZONES1_COST_' . $i;
        $keys[] = 'MODULE_SHIPPING_ZONES1_HANDLING_' . $i;
      }
 
      return $keys;
    }
  }
?>
 
 
Any assistance would be much appreciated :) 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...