Quick Search:

View

Revision:

Diff

Diff from 831 to:

Annotations

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

Annotated File View

hpdl
1
1 <?php
2 /*
mattice
151
3   $Id: shipping.php 831 2006-08-29 12:48:40Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
410
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
hpdl
443
13   class osC_Shipping {
14     var $_modules = array(),
15         $_selected_module,
16         $_quotes = array(),
17         $_group = 'shipping';
hpdl
1
18
19 // class constructor
hpdl
443
20     function osC_Shipping($module = '') {
21       global $osC_Database, $osC_Language;
hpdl
383
22
hpdl
443
23       if (isset($_SESSION['osC_Shipping_data']) === false) {
24         $_SESSION['osC_Shipping_data'] = array('quotes' => array(),
25                                                'cartID' => null);
26       }
hpdl
1
27
hpdl
443
28       $this->_quotes =& $_SESSION['osC_Shipping_data']['quotes'];
29       $this->_cartID =& $_SESSION['osC_Shipping_data']['cartID'];
hpdl
1
30
hpdl
443
31       $Qmodules = $osC_Database->query('select code from :table_templates_boxes where modules_group = "shipping"');
32       $Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
33       $Qmodules->setCache('modules-shipping');
34       $Qmodules->execute();
35
36       while ($Qmodules->next()) {
37         $this->_modules[] = $Qmodules->value('code');
38       }
39
40       $Qmodules->freeResult();
41
42       if (empty($this->_modules) === false) {
43         if ((empty($module) === false) && in_array(substr($module, 0, strpos($module, '_')), $this->_modules)) {
44           $this->_selected_module = $module;
45           $this->_modules = array(substr($module, 0, strpos($module, '_')));
hpdl
1
46         }
47
hpdl
410
48         $osC_Language->load('modules-shipping');
49
hpdl
443
50         foreach ($this->_modules as $module) {
51           $module_class = 'osC_Shipping_' . $module;
hpdl
1
52
hpdl
443
53           if (class_exists($module_class) === false) {
54             include('includes/modules/shipping/' . $module . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
55           }
56
57           $GLOBALS[$module_class] = new $module_class();
58           $GLOBALS[$module_class]->initialize();
hpdl
1
59         }
hpdl
443
60
61         usort($this->_modules, array('osC_Shipping', '_usortModules'));
hpdl
1
62       }
hpdl
443
63
64       $this->_calculate();
hpdl
1
65     }
66
hpdl
443
67 // class methods
68     function getCode() {
69       return $this->_code;
70     }
hpdl
1
71
hpdl
443
72     function getTitle() {
73       return $this->_title;
74     }
hpdl
1
75
hpdl
443
76     function getDescription() {
77       return $this->_description;
78     }
hpdl
1
79
hpdl
637
80     function isEnabled() {
hpdl
443
81       return $this->_status;
82     }
83
84     function getSortOrder() {
85       return $this->_sort_order;
86     }
87
88     function hasQuotes() {
89       return !empty($this->_quotes);
90     }
91
92     function numberOfQuotes() {
93       $total_quotes = 0;
94
95       foreach ($this->_quotes as $quotes) {
96         $total_quotes += sizeof($quotes['methods']);
97       }
98
99       return $total_quotes;
100     }
101
102     function getQuotes() {
103       return $this->_quotes;
104     }
105
106     function getQuote($module = '') {
107       if (empty($module)) {
108         $module = $this->_selected_module;
109       }
110
111       list($module_id, $method_id) = explode('_', $module);
112
113       $rate = array();
114
115       foreach ($this->_quotes as $quote) {
116         if ($quote['id'] == $module_id) {
117           foreach ($quote['methods'] as $method) {
118             if ($method['id'] == $method_id) {
119               $rate = array('id' => $module,
120                             'title' => $quote['module'] . ((empty($method['title']) === false) ? ' (' . $method['title'] . ')' : ''),
121                             'cost' => $method['cost'],
hpdl
831
122                             'tax_class_id' => $quote['tax_class_id'],
123                             'is_cheapest' => null);
hpdl
443
124
125               break 2;
126             }
127           }
hpdl
1
128         }
hpdl
443
129       }
hpdl
1
130
hpdl
443
131       return $rate;
132     }
133
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);
145           }
hpdl
1
146         }
hpdl
443
147       }
hpdl
1
148
hpdl
443
149       return $rate;
150     }
hpdl
1
151
hpdl
443
152     function hasActive() {
153       static $has_active;
154
155       if (isset($has_active) === false) {
156         $has_active = false;
157
158         foreach ($this->_modules as $module) {
hpdl
637
159           if ($GLOBALS['osC_Shipping_' . $module]->isEnabled()) {
hpdl
443
160             $has_active = true;
161             break;
hpdl
1
162           }
163         }
hpdl
443
164       }
hpdl
1
165
hpdl
443
166       return $has_active;
167     }
168
169     function _calculate() {
170       global $osC_ShoppingCart;
171
172       if ($this->_cartID != $osC_ShoppingCart->getCartID()) {
173         $this->_cartID = $osC_ShoppingCart->getCartID();
174
175         $this->_quotes = array();
176
177         if (is_array($this->_modules)) {
178           $include_quotes = array();
179
hpdl
637
180           if (defined('MODULE_SHIPPING_FREE_STATUS') && (MODULE_SHIPPING_FREE_STATUS == 'True') && $GLOBALS['osC_Shipping_free']->isEnabled()) {
hpdl
443
181             $include_quotes[] = 'osC_Shipping_free';
182           } else {
183             foreach ($this->_modules as $module) {
hpdl
637
184               if ($GLOBALS['osC_Shipping_' . $module]->isEnabled()) {
hpdl
443
185                 $include_quotes[] = 'osC_Shipping_' . $module;
hpdl
1
186               }
187             }
188           }
189
hpdl
443
190           foreach ($include_quotes as $module) {
191             $quotes = $GLOBALS[$module]->quote();
192
193             if (is_array($quotes)) {
194               $this->_quotes[] = $quotes;
hpdl
1
195             }
196           }
197         }
hpdl
443
198       }
199     }
hpdl
1
200
hpdl
443
201     function _usortModules($a, $b) {
202       if ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() == $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) {
203         return strnatcasecmp($GLOBALS['osC_Shipping_' . $a]->getTitle(), $GLOBALS['osC_Shipping_' . $a]->getTitle());
hpdl
1
204       }
hpdl
443
205
206       return ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() < $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) ? -1 : 1;
hpdl
1
207     }
208   }
209 ?>