Quick Search:

View

Revision:

Diff

Diff from 421 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/shipping.php

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
153
3   $Id: shipping.php 421 2006-02-08 17:53:17Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
404
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
hpdl
421
13   class osC_Shipping {
14     var $_modules = array(),
15         $_quotes = array(),
16         $_shipping_boxes = 1,
17         $_shipping_weight = 0;
hpdl
1
18
19 // class constructor
hpdl
421
20     function osC_Shipping($module = '') {
hpdl
377
21       global $osC_Language;
22
hpdl
421
23       if (isset($_SESSION['osC_Shipping_data']) === false) {
24         $_SESSION['osC_Shipping_data'] = array('shipping_boxes' => 1,
25                                                'shipping_weight' => 0,
26                                                'quotes' => array());
27       }
hpdl
1
28
hpdl
421
29       $this->_shipping_boxes =& $_SESSION['osC_Shipping_data']['shipping_boxes'];
30       $this->_shipping_weight =& $_SESSION['osC_Shipping_data']['shipping_weight'];
31       $this->_quotes =& $_SESSION['osC_Shipping_data']['quotes'];
32
33       if (defined('MODULE_SHIPPING_INSTALLED') && (osc_empty(MODULE_SHIPPING_INSTALLED) === false)) {
34         $this->_modules = explode(';', MODULE_SHIPPING_INSTALLED);
35
hpdl
1
36         $include_modules = array();
37
hpdl
421
38         if ( (empty($module) === false) && (in_array(substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($_SERVER['PHP_SELF'], (strrpos($_SERVER['PHP_SELF'], '.')+1)), $this->_modules)) ) {
hpdl
1
39           $include_modules[] = array('class' => substr($module['id'], 0, strpos($module['id'], '_')), 'file' => substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($_SERVER['PHP_SELF'], (strrpos($_SERVER['PHP_SELF'], '.')+1)));
40         } else {
hpdl
421
41           foreach ($this->_modules as $value) {
hpdl
1
42             $class = substr($value, 0, strrpos($value, '.'));
43             $include_modules[] = array('class' => $class, 'file' => $value);
44           }
45         }
46
hpdl
404
47         $osC_Language->load('modules-shipping');
48
hpdl
421
49         foreach ($include_modules as $module) {
50           include('includes/modules/shipping/' . $module['file']);
hpdl
1
51
hpdl
421
52           $GLOBALS[$module['class']] = new $module['class'];
hpdl
1
53         }
54       }
55     }
56
hpdl
421
57     function calculateQuotes($method = '', $module = '') {
58       global $osC_ShoppingCart;
hpdl
1
59
hpdl
421
60       $this->_quotes = array();
hpdl
1
61
hpdl
421
62       if (is_array($this->_modules)) {
63         $this->_shipping_weight = $osC_ShoppingCart->getWeight();
hpdl
1
64
hpdl
421
65         if (SHIPPING_BOX_WEIGHT >= ($this->_shipping_weight * SHIPPING_BOX_PADDING/100)) {
66           $this->_shipping_weight = $this->_shipping_weight + SHIPPING_BOX_WEIGHT;
hpdl
1
67         } else {
hpdl
421
68           $this->_shipping_weight = $this->_shipping_weight + ($this->_shipping_weight * SHIPPING_BOX_PADDING/100);
hpdl
1
69         }
70
hpdl
421
71         if ($this->_shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
72           $this->_shipping_boxes = ceil($this->_shipping_weight / SHIPPING_MAX_WEIGHT);
73           $this->_shipping_weight = $this->_shipping_weight / $this->_shipping_boxes;
hpdl
1
74         }
75
76         $include_quotes = array();
77
hpdl
421
78         foreach ($this->_modules as $value) {
hpdl
1
79           $class = substr($value, 0, strrpos($value, '.'));
80           if (tep_not_null($module)) {
81             if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) {
82               $include_quotes[] = $class;
83             }
84           } elseif ($GLOBALS[$class]->enabled) {
85             $include_quotes[] = $class;
86           }
87         }
88
hpdl
421
89         foreach ($include_quotes as $module) {
90           $quotes = $GLOBALS[$module]->quote($method);
91
92           if (is_array($quotes)) {
93             $this->_quotes[] = $quotes;
94           }
hpdl
1
95         }
96       }
hpdl
421
97     }
hpdl
1
98
hpdl
421
99     function hasQuotes() {
100       return !empty($this->_quotes);
hpdl
1
101     }
102
hpdl
421
103     function getQuotes($method = '', $module = '') {
104       if ( (empty($method) === false) && (empty($module) === false) ) {
105         foreach ($this->_quotes as $quote) {
106           if ($quote['id'] == $module) {
107             foreach ($quote['methods'] as $quote_method) {
108               if ($quote_method['id'] == $method) {
109                 return array('id' => $quote['id'],
110                              'module' => $quote['module'],
111                              'methods' => $quote_method,
112                              'tax' => $quote['tax']);
113               }
114             }
115           }
116         }
117       }
118
119       return $this->_quotes;
120     }
121
122     function getCheapestQuote() {
123       if (is_array($this->_modules)) {
hpdl
1
124         $rates = array();
125
hpdl
421
126         foreach ($this->_modules as $value) {
hpdl
1
127           $class = substr($value, 0, strrpos($value, '.'));
128           if ($GLOBALS[$class]->enabled) {
129             $quotes = $GLOBALS[$class]->quotes;
hpdl
421
130
hpdl
1
131             for ($i=0, $n=sizeof($quotes['methods']); $i<$n; $i++) {
132               if (isset($quotes['methods'][$i]['cost']) && tep_not_null($quotes['methods'][$i]['cost'])) {
133                 $rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
134                                  'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')',
135                                  'cost' => $quotes['methods'][$i]['cost']);
136               }
137             }
138           }
139         }
140
141         $cheapest = false;
hpdl
421
142
hpdl
1
143         for ($i=0, $n=sizeof($rates); $i<$n; $i++) {
144           if (is_array($cheapest)) {
145             if ($rates[$i]['cost'] < $cheapest['cost']) {
146               $cheapest = $rates[$i];
147             }
148           } else {
149             $cheapest = $rates[$i];
150           }
151         }
152
153         return $cheapest;
154       }
155     }
156   }
157 ?>