[ Index ]
 

Code source de osCommerce 2.2ms2-060817

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/catalog/includes/modules/shipping/ -> zones.php (source)

   1  <?php
   2  /*
   3  
   4    $Id: zones.php,v 1.20 2003/06/15 19:48:09 thomasamoulton Exp $
   5  
   6    osCommerce, Open Source E-Commerce Solutions
   7    http://www.oscommerce.com
   8  
   9    Copyright (c) 2003 osCommerce
  10  
  11    Released under the GNU General Public License
  12  
  13    USAGE
  14    By default, the module comes with support for 1 zone.  This can be
  15    easily changed by editing the line below in the zones constructor 
  16    that defines $this->num_zones.
  17  
  18    Next, you will want to activate the module by going to the Admin screen,
  19    clicking on Modules, then clicking on Shipping.  A list of all shipping
  20    modules should appear.  Click on the green dot next to the one labeled 
  21    zones.php.  A list of settings will appear to the right.  Click on the
  22    Edit button. 
  23  
  24    PLEASE NOTE THAT YOU WILL LOSE YOUR CURRENT SHIPPING RATES AND OTHER 
  25    SETTINGS IF YOU TURN OFF THIS SHIPPING METHOD.  Make sure you keep a 
  26    backup of your shipping settings somewhere at all times.
  27  
  28    If you want an additional handling charge applied to orders that use this
  29    method, set the Handling Fee field.
  30  
  31    Next, you will need to define which countries are in each zone.  Determining
  32    this might take some time and effort.  You should group a set of countries
  33    that has similar shipping charges for the same weight.  For instance, when
  34    shipping from the US, the countries of Japan, Australia, New Zealand, and 
  35    Singapore have similar shipping rates.  As an example, one of my customers
  36    is using this set of zones:
  37      1: USA
  38      2: Canada
  39      3: Austria, Belgium, Great Britain, France, Germany, Greenland, Iceland,
  40         Ireland, Italy, Norway, Holland/Netherlands, Denmark, Poland, Spain,
  41         Sweden, Switzerland, Finland, Portugal, Israel, Greece
  42      4: Japan, Australia, New Zealand, Singapore
  43      5: Taiwan, China, Hong Kong
  44  
  45    When you enter these country lists, enter them into the Zone X Countries
  46    fields, where "X" is the number of the zone.  They should be entered as
  47    two character ISO country codes in all capital letters.  They should be
  48    separated by commas with no spaces or other punctuation. For example:
  49      1: US
  50      2: CA
  51      3: AT,BE,GB,FR,DE,GL,IS,IE,IT,NO,NL,DK,PL,ES,SE,CH,FI,PT,IL,GR
  52      4: JP,AU,NZ,SG
  53      5: TW,CN,HK
  54  
  55    Now you need to set up the shipping rate tables for each zone.  Again,
  56    some time and effort will go into setting the appropriate rates.  You
  57    will define a set of weight ranges and the shipping price for each
  58    range.  For instance, you might want an order than weighs more than 0
  59    and less than or equal to 3 to cost 5.50 to ship to a certain zone.  
  60    This would be defined by this:  3:5.5
  61  
  62    You should combine a bunch of these rates together in a comma delimited
  63    list and enter them into the "Zone X Shipping Table" fields where "X" 
  64    is the zone number.  For example, this might be used for Zone 1:
  65      1:3.5,2:3.95,3:5.2,4:6.45,5:7.7,6:10.4,7:11.85, 8:13.3,9:14.75,10:16.2,11:17.65,
  66      12:19.1,13:20.55,14:22,15:23.45
  67  
  68    The above example includes weights over 0 and up to 15.  Note that
  69    units are not specified in this explanation since they should be
  70    specific to your locale.
  71  
  72    CAVEATS
  73    At this time, it does not deal with weights that are above the highest amount
  74    defined.  This will probably be the next area to be improved with the
  75    module.  For now, you could have one last very high range with a very
  76    high shipping rate to discourage orders of that magnitude.  For 
  77    instance:  999:1000
  78  
  79    If you want to be able to ship to any country in the world, you will 
  80    need to enter every country code into the Country fields. For most
  81    shops, you will not want to enter every country.  This is often 
  82    because of too much fraud from certain places. If a country is not
  83    listed, then the module will add a $0.00 shipping charge and will
  84    indicate that shipping is not available to that destination.  
  85    PLEASE NOTE THAT THE ORDER CAN STILL BE COMPLETED AND PROCESSED!
  86  
  87    It appears that the osC shipping system automatically rounds the 
  88    shipping weight up to the nearest whole unit.  This makes it more
  89    difficult to design precise shipping tables.  If you want to, you 
  90    can hack the shipping.php file to get rid of the rounding.
  91  
  92    Lastly, there is a limit of 255 characters on each of the Zone
  93    Shipping Tables and Zone Countries. 
  94  
  95  */
  96  
  97    class zones {
  98      var $code, $title, $description, $enabled, $num_zones;
  99  
 100  // class constructor
 101      function zones() {
 102        $this->code = 'zones';
 103        $this->title = MODULE_SHIPPING_ZONES_TEXT_TITLE;
 104        $this->description = MODULE_SHIPPING_ZONES_TEXT_DESCRIPTION;
 105        $this->sort_order = MODULE_SHIPPING_ZONES_SORT_ORDER;
 106        $this->icon = '';
 107        $this->tax_class = MODULE_SHIPPING_ZONES_TAX_CLASS;
 108        $this->enabled = ((MODULE_SHIPPING_ZONES_STATUS == 'True') ? true : false);
 109  
 110        // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
 111        $this->num_zones = 1;
 112      }
 113  
 114  // class methods
 115      function quote($method = '') {
 116        global $order, $shipping_weight, $shipping_num_boxes;
 117  
 118        $dest_country = $order->delivery['country']['iso_code_2'];
 119        $dest_zone = 0;
 120        $error = false;
 121  
 122        for ($i=1; $i<=$this->num_zones; $i++) {
 123          $countries_table = constant('MODULE_SHIPPING_ZONES_COUNTRIES_' . $i);
 124          $country_zones = split("[,]", $countries_table);
 125          if (in_array($dest_country, $country_zones)) {
 126            $dest_zone = $i;
 127            break;
 128          }
 129        }
 130  
 131        if ($dest_zone == 0) {
 132          $error = true;
 133        } else {
 134          $shipping = -1;
 135          $zones_cost = constant('MODULE_SHIPPING_ZONES_COST_' . $dest_zone);
 136  
 137          $zones_table = split("[:,]" , $zones_cost);
 138          $size = sizeof($zones_table);
 139          for ($i=0; $i<$size; $i+=2) {
 140            if ($shipping_weight <= $zones_table[$i]) {
 141              $shipping = $zones_table[$i+1];
 142              $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country . ' : ' . $shipping_weight . ' ' . MODULE_SHIPPING_ZONES_TEXT_UNITS;
 143              break;
 144            }
 145          }
 146  
 147          if ($shipping == -1) {
 148            $shipping_cost = 0;
 149            $shipping_method = MODULE_SHIPPING_ZONES_UNDEFINED_RATE;
 150          } else {
 151            $shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone);
 152          }
 153        }
 154  
 155        $this->quotes = array('id' => $this->code,
 156                              'module' => MODULE_SHIPPING_ZONES_TEXT_TITLE,
 157                              'methods' => array(array('id' => $this->code,
 158                                                       'title' => $shipping_method,
 159                                                       'cost' => $shipping_cost)));
 160  
 161        if ($this->tax_class > 0) {
 162          $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
 163        }
 164  
 165        if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);
 166  
 167        if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_ZONES_INVALID_ZONE;
 168  
 169        return $this->quotes;
 170      }
 171  
 172      function check() {
 173        if (!isset($this->_check)) {
 174          $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_ZONES_STATUS'");
 175          $this->_check = tep_db_num_rows($check_query);
 176        }
 177        return $this->_check;
 178      }
 179  
 180      function install() {
 181        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())");
 182        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())");
 183        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())");
 184        for ($i = 1; $i <= $this->num_zones; $i++) {
 185          $default_countries = '';
 186          if ($i == 1) {
 187            $default_countries = 'US,CA';
 188          }
 189          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())");
 190          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())");
 191          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())");
 192        }
 193      }
 194  
 195      function remove() {
 196        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 197      }
 198  
 199      function keys() {
 200        $keys = array('MODULE_SHIPPING_ZONES_STATUS', 'MODULE_SHIPPING_ZONES_TAX_CLASS', 'MODULE_SHIPPING_ZONES_SORT_ORDER');
 201  
 202        for ($i=1; $i<=$this->num_zones; $i++) {
 203          $keys[] = 'MODULE_SHIPPING_ZONES_COUNTRIES_' . $i;
 204          $keys[] = 'MODULE_SHIPPING_ZONES_COST_' . $i;
 205          $keys[] = 'MODULE_SHIPPING_ZONES_HANDLING_' . $i;
 206        }
 207  
 208        return $keys;
 209      }
 210    }
 211  ?>


Généré le : Mon Nov 26 19:48:25 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics