hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
153
|
3
|
$Id: shipping.php 864 2006-08-30 01:21:58Z 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(),
|
hpdl
|
439
|
15
|
$_selected_module,
|
hpdl
|
421
|
16
|
$_quotes = array(),
|
hpdl
|
432
|
17
|
$_group = 'shipping';
|
hpdl
|
1
|
18
|
|
|
19
|
// class constructor
|
hpdl
|
421
|
20
|
function osC_Shipping($module = '') {
|
hpdl
|
425
|
21
|
global $osC_Database, $osC_Language;
|
hpdl
|
377
|
22
|
|
hpdl
|
421
|
23
|
if (isset($_SESSION['osC_Shipping_data']) === false) {
|
hpdl
|
439
|
24
|
$_SESSION['osC_Shipping_data'] = array('quotes' => array(),
|
|
25
|
'cartID' => null);
|
hpdl
|
421
|
26
|
}
|
hpdl
|
1
|
27
|
|
hpdl
|
421
|
28
|
$this->_quotes =& $_SESSION['osC_Shipping_data']['quotes'];
|
hpdl
|
439
|
29
|
$this->_cartID =& $_SESSION['osC_Shipping_data']['cartID'];
|
hpdl
|
421
|
30
|
|
hpdl
|
425
|
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();
|
hpdl
|
421
|
35
|
|
hpdl
|
425
|
36
|
while ($Qmodules->next()) {
|
|
37
|
$this->_modules[] = $Qmodules->value('code');
|
|
38
|
}
|
|
39
|
|
|
40
|
$Qmodules->freeResult();
|
|
41
|
|
|
42
|
if (empty($this->_modules) === false) {
|
hpdl
|
439
|
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
|
404
|
48
|
$osC_Language->load('modules-shipping');
|
|
49
|
|
hpdl
|
427
|
50
|
foreach ($this->_modules as $module) {
|
|
51
|
$module_class = 'osC_Shipping_' . $module;
|
|
52
|
|
hpdl
|
439
|
53
|
if (class_exists($module_class) === false) {
|
|
54
|
include('includes/modules/shipping/' . $module . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
|
|
55
|
}
|
|
56
|
|
hpdl
|
427
|
57
|
$GLOBALS[$module_class] = new $module_class();
|
|
58
|
$GLOBALS[$module_class]->initialize();
|
hpdl
|
1
|
59
|
}
|
hpdl
|
427
|
60
|
|
|
61
|
usort($this->_modules, array('osC_Shipping', '_usortModules'));
|
hpdl
|
1
|
62
|
}
|
hpdl
|
439
|
63
|
|
|
64
|
$this->_calculate();
|
hpdl
|
1
|
65
|
}
|
|
66
|
|
hpdl
|
432
|
67
|
// class methods
|
|
68
|
function getCode() {
|
|
69
|
return $this->_code;
|
|
70
|
}
|
|
71
|
|
|
72
|
function getTitle() {
|
|
73
|
return $this->_title;
|
|
74
|
}
|
|
75
|
|
|
76
|
function getDescription() {
|
|
77
|
return $this->_description;
|
|
78
|
}
|
|
79
|
|
hpdl
|
620
|
80
|
function isEnabled() {
|
hpdl
|
432
|
81
|
return $this->_status;
|
|
82
|
}
|
|
83
|
|
|
84
|
function getSortOrder() {
|
|
85
|
return $this->_sort_order;
|
|
86
|
}
|
|
87
|
|
hpdl
|
421
|
88
|
function hasQuotes() {
|
|
89
|
return !empty($this->_quotes);
|
hpdl
|
1
|
90
|
}
|
|
91
|
|
hpdl
|
422
|
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
|
|
hpdl
|
439
|
102
|
function getQuotes() {
|
|
103
|
return $this->_quotes;
|
|
104
|
}
|
hpdl
|
425
|
105
|
|
hpdl
|
439
|
106
|
function getQuote($module = '') {
|
|
107
|
if (empty($module)) {
|
|
108
|
$module = $this->_selected_module;
|
hpdl
|
421
|
109
|
}
|
|
110
|
|
hpdl
|
439
|
111
|
list($module_id, $method_id) = explode('_', $module);
|
hpdl
|
421
|
112
|
|
hpdl
|
439
|
113
|
$rate = array();
|
hpdl
|
1
|
114
|
|
hpdl
|
439
|
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
|
830
|
122
|
'tax_class_id' => $quote['tax_class_id'],
|
|
123
|
'is_cheapest' => null);
|
hpdl
|
421
|
124
|
|
hpdl
|
439
|
125
|
break 2;
|
hpdl
|
1
|
126
|
}
|
|
127
|
}
|
|
128
|
}
|
hpdl
|
439
|
129
|
}
|
hpdl
|
1
|
130
|
|
hpdl
|
439
|
131
|
return $rate;
|
|
132
|
}
|
hpdl
|
421
|
133
|
|
hpdl
|
439
|
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'],
|
hpdl
|
864
|
144
|
'is_cheapest' => false);
|
hpdl
|
1
|
145
|
}
|
|
146
|
}
|
|
147
|
}
|
hpdl
|
439
|
148
|
|
hpdl
|
864
|
149
|
if (!empty($rate)) {
|
|
150
|
$rate['is_cheapest'] = true;
|
|
151
|
}
|
|
152
|
|
hpdl
|
439
|
153
|
return $rate;
|
hpdl
|
1
|
154
|
}
|
hpdl
|
425
|
155
|
|
|
156
|
function hasActive() {
|
|
157
|
static $has_active;
|
|
158
|
|
|
159
|
if (isset($has_active) === false) {
|
|
160
|
$has_active = false;
|
|
161
|
|
|
162
|
foreach ($this->_modules as $module) {
|
hpdl
|
620
|
163
|
if ($GLOBALS['osC_Shipping_' . $module]->isEnabled()) {
|
hpdl
|
425
|
164
|
$has_active = true;
|
|
165
|
break;
|
|
166
|
}
|
|
167
|
}
|
|
168
|
}
|
|
169
|
|
|
170
|
return $has_active;
|
|
171
|
}
|
|
172
|
|
hpdl
|
439
|
173
|
function _calculate() {
|
|
174
|
global $osC_ShoppingCart;
|
|
175
|
|
|
176
|
if ($this->_cartID != $osC_ShoppingCart->getCartID()) {
|
|
177
|
$this->_cartID = $osC_ShoppingCart->getCartID();
|
|
178
|
|
|
179
|
$this->_quotes = array();
|
|
180
|
|
|
181
|
if (is_array($this->_modules)) {
|
|
182
|
$include_quotes = array();
|
|
183
|
|
hpdl
|
864
|
184
|
if (defined('MODULE_SHIPPING_FREE_STATUS') && isset($GLOBALS['osC_Shipping_free']) && $GLOBALS['osC_Shipping_free']->isEnabled()) {
|
hpdl
|
439
|
185
|
$include_quotes[] = 'osC_Shipping_free';
|
|
186
|
} else {
|
|
187
|
foreach ($this->_modules as $module) {
|
hpdl
|
620
|
188
|
if ($GLOBALS['osC_Shipping_' . $module]->isEnabled()) {
|
hpdl
|
439
|
189
|
$include_quotes[] = 'osC_Shipping_' . $module;
|
|
190
|
}
|
|
191
|
}
|
|
192
|
}
|
|
193
|
|
|
194
|
foreach ($include_quotes as $module) {
|
|
195
|
$quotes = $GLOBALS[$module]->quote();
|
|
196
|
|
|
197
|
if (is_array($quotes)) {
|
|
198
|
$this->_quotes[] = $quotes;
|
|
199
|
}
|
|
200
|
}
|
|
201
|
}
|
|
202
|
}
|
|
203
|
}
|
|
204
|
|
hpdl
|
427
|
205
|
function _usortModules($a, $b) {
|
hpdl
|
432
|
206
|
if ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() == $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) {
|
|
207
|
return strnatcasecmp($GLOBALS['osC_Shipping_' . $a]->getTitle(), $GLOBALS['osC_Shipping_' . $a]->getTitle());
|
hpdl
|
427
|
208
|
}
|
|
209
|
|
hpdl
|
432
|
210
|
return ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() < $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) ? -1 : 1;
|
hpdl
|
427
|
211
|
}
|
hpdl
|
1
|
212
|
}
|
|
213
|
?>
|