Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

438
 
439
 
439
 
shipping.php
_> 11 <?php
  22 /*
<> 3 -  $Id: shipping.php 438 2006-02-16 14:50:54Z hpdl $
   3+  $Id: shipping.php 439 2006-02-19 16:33:18Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
     
 !
1212 
  1313   class osC_Shipping {
  1414     var $_modules = array(),
<>  15+        $_selected_module,
1516         $_quotes = array(),
<> 16 -        $_shipping_boxes = 1,
  17 -        $_shipping_weight = 0,
1817         $_keys,
  1918         $_group = 'shipping';
  2019 
     
 !
2322       global $osC_Database, $osC_Language;
  2423 
  2524       if (isset($_SESSION['osC_Shipping_data']) === false) {
<> 26 -        $_SESSION['osC_Shipping_data'] = array('shipping_boxes' => 1,
  27 -                                               'shipping_weight' => 0,
  28 -                                               'quotes' => array());
   25+        $_SESSION['osC_Shipping_data'] = array('quotes' => array(),
   26+                                               'cartID' => null);
2927       }
  3028 
<> 31 -      $this->_shipping_boxes =& $_SESSION['osC_Shipping_data']['shipping_boxes'];
  32 -      $this->_shipping_weight =& $_SESSION['osC_Shipping_data']['shipping_weight'];
3329       $this->_quotes =& $_SESSION['osC_Shipping_data']['quotes'];
<>  30+      $this->_cartID =& $_SESSION['osC_Shipping_data']['cartID'];
3431 
  3532       $Qmodules = $osC_Database->query('select code from :table_templates_boxes where modules_group = "shipping"');
  3633       $Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
     
 !
4441       $Qmodules->freeResult();
  4542 
  4643       if (empty($this->_modules) === false) {
<> 47 -        if ((empty($module) === false) && in_array(substr($module['id'], 0, strpos($module['id'], '_')), $this->_modules)) {
  48 -          $this->_modules = array($module['id']);
   44+        if ((empty($module) === false) && in_array(substr($module, 0, strpos($module, '_')), $this->_modules)) {
   45+          $this->_selected_module = $module;
   46+          $this->_modules = array(substr($module, 0, strpos($module, '_')));
4947         }
  5048 
  5149         $osC_Language->load('modules-shipping');
  5250 
  5351         foreach ($this->_modules as $module) {
<> 54 -          include('includes/modules/shipping/' . $module . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
  55 -
5652           $module_class = 'osC_Shipping_' . $module;
  5753 
<>  54+          if (class_exists($module_class) === false) {
   55+            include('includes/modules/shipping/' . $module . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
   56+          }
   57+
5858           $GLOBALS[$module_class] = new $module_class();
  5959           $GLOBALS[$module_class]->initialize();
  6060         }
  6161 
  6262         usort($this->_modules, array('osC_Shipping', '_usortModules'));
  6363       }
<>  64+
   65+      $this->_calculate();
6466     }
  6567 
  6668 // class methods
     
 !
8486       return $this->_sort_order;
  8587     }
  8688 
<> 87 -    function calculateQuotes() {
  88 -      global $osC_ShoppingCart;
  89 -
  90 -      $this->_quotes = array();
  91 -
  92 -      if (is_array($this->_modules)) {
  93 -        $this->_shipping_weight = $osC_ShoppingCart->getWeight();
  94 -
  95 -        if (SHIPPING_BOX_WEIGHT >= ($this->_shipping_weight * SHIPPING_BOX_PADDING/100)) {
  96 -          $this->_shipping_weight = $this->_shipping_weight + SHIPPING_BOX_WEIGHT;
  97 -        } else {
  98 -          $this->_shipping_weight = $this->_shipping_weight + ($this->_shipping_weight * SHIPPING_BOX_PADDING/100);
  99 -        }
  100 -
  101 -        if ($this->_shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
  102 -          $this->_shipping_boxes = ceil($this->_shipping_weight / SHIPPING_MAX_WEIGHT);
  103 -          $this->_shipping_weight = $this->_shipping_weight / $this->_shipping_boxes;
  104 -        }
  105 -
  106 -        $include_quotes = array();
  107 -
  108 -        if (defined('MODULE_SHIPPING_FREE_STATUS') && (MODULE_SHIPPING_FREE_STATUS == 'True') && ($GLOBALS['osC_Shipping_free']->getStatus() === true)) {
  109 -          $include_quotes[] = 'free';
  110 -        } else {
  111 -          foreach ($this->_modules as $module) {
  112 -            if ($GLOBALS['osC_Shipping_' . $module]->getStatus() === true) {
  113 -              $include_quotes[] = 'osC_Shipping_' . $module;
  114 -            }
  115 -          }
  116 -        }
  117 -
  118 -        foreach ($include_quotes as $module) {
  119 -          $quotes = $GLOBALS[$module]->quote();
  120 -
  121 -          if (is_array($quotes)) {
  122 -            $this->_quotes[] = $quotes;
  123 -          }
  124 -        }
  125 -      }
  126 -    }
  127 -
12889     function hasQuotes() {
  12990       return !empty($this->_quotes);
  13091     }
     
 !
139100       return $total_quotes;
  140101     }
  141102 
<> 142 -    function getQuotes($module = '') {
  143 -      if (empty($module) === false) {
  144 -        list($module, $method) = explode('_', $module);
   103+    function getQuotes() {
   104+      return $this->_quotes;
   105+    }
145106 
<> 146 -        foreach ($this->_quotes as $quote) {
  147 -          if ($quote['id'] == $module) {
  148 -            foreach ($quote['methods'] as $quote_method) {
  149 -              if ($quote_method['id'] == $method) {
  150 -                return array('id' => $quote['id'],
  151 -                             'module' => $quote['module'],
  152 -                             'methods' => $quote_method,
  153 -                             'tax_class_id' => $quote['tax_class_id']);
  154 -              }
  155 -            }
  156 -          }
  157 -        }
   107+    function getQuote($module = '') {
   108+      if (empty($module)) {
   109+        $module = $this->_selected_module;
158110       }
  159111 
<> 160 -      return $this->_quotes;
  161 -    }
   112+      list($module_id, $method_id) = explode('_', $module);
162113 
<> 163 -    function getCheapestQuote() {
  164 -      if (is_array($this->_modules)) {
  165 -        $rates = array();
   114+      $rate = array();
166115 
<> 167 -        foreach ($this->_modules as $value) {
  168 -          $class = 'osC_Shipping_' . $value;
  169 -          if ($GLOBALS[$class]->getStatus() === true) {
  170 -            $quotes = $GLOBALS[$class]->quotes;
   116+      foreach ($this->_quotes as $quote) {
   117+        if ($quote['id'] == $module_id) {
   118+          foreach ($quote['methods'] as $method) {
   119+            if ($method['id'] == $method_id) {
   120+              $rate = array('id' => $module,
   121+                            'title' => $quote['module'] . ((empty($method['title']) === false) ? ' (' . $method['title'] . ')' : ''),
   122+                            'cost' => $method['cost'],
   123+                            'tax_class_id' => $quote['tax_class_id']);
171124 
<> 172 -            for ($i=0, $n=sizeof($quotes['methods']); $i<$n; $i++) {
  173 -              if (isset($quotes['methods'][$i]['cost']) && tep_not_null($quotes['methods'][$i]['cost'])) {
  174 -                $rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
  175 -                                 'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')',
  176 -                                 'cost' => $quotes['methods'][$i]['cost'],
  177 -                                 'tax_class_id' => $quotes['tax_class_id']);
  178 -              }
   125+              break 2;
179126             }
  180127           }
  181128         }
<>  129+      }
182130 
<> 183 -        $cheapest = false;
   131+      return $rate;
   132+    }
184133 
<> 185 -        for ($i=0, $n=sizeof($rates); $i<$n; $i++) {
  186 -          if (is_array($cheapest)) {
  187 -            if ($rates[$i]['cost'] < $cheapest['cost']) {
  188 -              $cheapest = $rates[$i];
  189 -            }
  190 -          } else {
  191 -            $cheapest = $rates[$i];
   134+    function getCheapestQuote() {
   135+      $rate = array();
   136+
   137+      foreach ($this->_quotes as $quote) {
   138+        foreach ($quote['methods'] as $method) {
   139+          if (empty($rate) || ($method['cost'] < $rate['cost'])) {
   140+            $rate = array('id' => $quote['id'] . '_' . $method['id'],
   141+                          'title' => $quote['module'] . ((empty($method['title']) === false) ? ' (' . $method['title'] . ')' : ''),
   142+                          'cost' => $method['cost'],
   143+                          'tax_class_id' => $quote['tax_class_id'],
   144+                          'is_cheapest' => true);
192145           }
  193146         }
<> 194 -
  195 -        return $cheapest;
196147       }
<>  148+
   149+      return $rate;
197150     }
  198151 
  199152     function hasActive() {
     
 !
292245       }
  293246     }
  294247 
<>  248+    function _calculate() {
   249+      global $osC_ShoppingCart;
   250+
   251+      if ($this->_cartID != $osC_ShoppingCart->getCartID()) {
   252+        $this->_cartID = $osC_ShoppingCart->getCartID();
   253+
   254+        $this->_quotes = array();
   255+
   256+        if (is_array($this->_modules)) {
   257+          $include_quotes = array();
   258+
   259+          if (defined('MODULE_SHIPPING_FREE_STATUS') && (MODULE_SHIPPING_FREE_STATUS == 'True') && ($GLOBALS['osC_Shipping_free']->getStatus() === true)) {
   260+            $include_quotes[] = 'osC_Shipping_free';
   261+          } else {
   262+            foreach ($this->_modules as $module) {
   263+              if ($GLOBALS['osC_Shipping_' . $module]->getStatus() === true) {
   264+                $include_quotes[] = 'osC_Shipping_' . $module;
   265+              }
   266+            }
   267+          }
   268+
   269+          foreach ($include_quotes as $module) {
   270+            $quotes = $GLOBALS[$module]->quote();
   271+
   272+            if (is_array($quotes)) {
   273+              $this->_quotes[] = $quotes;
   274+            }
   275+          }
   276+        }
   277+      }
   278+    }
   279+
<_ 295280     function _usortModules($a, $b) {
  296281       if ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() == $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) {
  297282         return strnatcasecmp($GLOBALS['osC_Shipping_' . $a]->getTitle(), $GLOBALS['osC_Shipping_' . $a]->getTitle());