Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

I need help on is to set up my Shipping Modules


Tom knight

Recommended Posts

I need help on is in my Admin panel the setting for

Shipping Modules. When you enable a Shipping Modules like Flat Rate it show a '0'.

When you remove the Flat Rate Shipping Modules the '0' go away.

But when i enable Shipping Modules Rates Based on Regions there

are no '0' there.

Can anyone help find the fix for this?

 

Here the code for the Rates Based on Regions

 

 

<?php
/*
Set the number of regions you need with
$this->regions = xx;
*/

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 = DIR_WS_ICONS . 'shipping_ups.gif';
    $this->enabled = MODULE_SHIPPING_REGIONS_STATUS;
    // CUSTOMIZE THIS SETTING FOR THE NUMBER OF States NEEDED
    $this->regions = 5;
  }

// 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 = ($order_total_price * ($regions_table[$i+1] / 100));
           $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 = '------';
        $default_prices = '-------';
      }
      if ($i == 2) {
        $default_states_or_countries = '------';
        $default_prices = '-------';
      }
      if ($i == 3) {
        $default_states_or_countries = '------';
        $default_prices = '-------';
      }
      if ($i == 4) {
        $default_states_or_countries = '------';
        $default_prices = '-------';
      }
      if ($i == 5) {
        $default_states_or_countries = '------';
        $default_prices = '-------';
      }
      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;
  }
}
?>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...