[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/order_editor/ -> shipping.php (source)

   1  <?php
   2  /*
   3    $Id: shipping.php v5.0 07/19/2007 djmonkey1 Exp $
   4  
   5    osCommerce, Open Source E-Commerce Solutions
   6    http://www.oscommerce.com
   7  
   8    Copyright (c) 2003 osCommerce
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13    class shipping {
  14      var $modules;
  15  
  16  // class constructor
  17      function shipping($module = '') {
  18        global $language, $PHP_SELF;
  19  
  20        if (defined('MODULE_SHIPPING_INSTALLED') && tep_not_null(MODULE_SHIPPING_INSTALLED)) {
  21          $this->modules = explode(';', MODULE_SHIPPING_INSTALLED);
  22  
  23          $include_modules = array();
  24  
  25          if ( (tep_not_null($module)) && (in_array(substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)), $this->modules)) ) {
  26            $include_modules[] = array('class' => substr($module['id'], 0, strpos($module['id'], '_')), 'file' => substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)));
  27          } else {
  28            reset($this->modules);
  29            while (list(, $value) = each($this->modules)) {
  30              $class = substr($value, 0, strrpos($value, '.'));
  31              $include_modules[] = array('class' => $class, 'file' => $value);
  32            }
  33          }
  34  
  35          for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
  36            include(DIR_FS_CATALOG_LANGUAGES . $language . '/modules/shipping/' . $include_modules[$i]['file']);
  37            include(DIR_FS_CATALOG_MODULES . 'shipping/' . $include_modules[$i]['file']);
  38  
  39            $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
  40          }
  41        }
  42      }
  43  
  44      function quote($method = '', $module = '') {
  45        global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;
  46  
  47        $quotes_array = array();
  48  
  49        if (is_array($this->modules)) {
  50          $shipping_quoted = '';
  51          $shipping_num_boxes = 1;
  52          $shipping_weight = $total_weight;
  53  
  54          if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) {
  55            $shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT;
  56          } else {
  57            $shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100);
  58          }
  59  
  60          if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
  61            $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
  62            $shipping_weight = $shipping_weight/$shipping_num_boxes;
  63          }
  64  
  65          $include_quotes = array();
  66  
  67          reset($this->modules);
  68          while (list(, $value) = each($this->modules)) {
  69            $class = substr($value, 0, strrpos($value, '.'));
  70            if (tep_not_null($module)) {
  71              if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) {
  72                $include_quotes[] = $class;
  73              }
  74            } elseif ($GLOBALS[$class]->enabled) {
  75              $include_quotes[] = $class;
  76            }
  77          }
  78  
  79          $size = sizeof($include_quotes);
  80          for ($i=0; $i<$size; $i++) {
  81            $quotes = $GLOBALS[$include_quotes[$i]]->quote($method);
  82            if (is_array($quotes)) $quotes_array[] = $quotes;
  83          }
  84        }
  85  
  86        return $quotes_array;
  87      }
  88  
  89      function cheapest() {
  90        if (is_array($this->modules)) {
  91          $rates = array();
  92  
  93          reset($this->modules);
  94          while (list(, $value) = each($this->modules)) {
  95            $class = substr($value, 0, strrpos($value, '.'));
  96            if ($GLOBALS[$class]->enabled) {
  97              $quotes = $GLOBALS[$class]->quotes;
  98              for ($i=0, $n=sizeof($quotes['methods']); $i<$n; $i++) {
  99                if (isset($quotes['methods'][$i]['cost']) && tep_not_null($quotes['methods'][$i]['cost'])) {
 100                  $rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
 101                                   'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')',
 102                                   'cost' => $quotes['methods'][$i]['cost']);
 103                }
 104              }
 105            }
 106          }
 107  
 108          $cheapest = false;
 109          for ($i=0, $n=sizeof($rates); $i<$n; $i++) {
 110            if (is_array($cheapest)) {
 111              if ($rates[$i]['cost'] < $cheapest['cost']) {
 112                $cheapest = $rates[$i];
 113              }
 114            } else {
 115              $cheapest = $rates[$i];
 116            }
 117          }
 118  
 119          return $cheapest;
 120        }
 121      }
 122    }
 123  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7