hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
153
|
3
|
$Id: shipping.php 438 2006-02-16 14:50:54Z 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,
|
hpdl
|
425
|
17
|
$_shipping_weight = 0,
|
hpdl
|
432
|
18
|
$_keys,
|
|
19
|
$_group = 'shipping';
|
hpdl
|
1
|
20
|
|
|
21
|
// class constructor
|
hpdl
|
421
|
22
|
function osC_Shipping($module = '') {
|
hpdl
|
425
|
23
|
global $osC_Database, $osC_Language;
|
hpdl
|
377
|
24
|
|
hpdl
|
421
|
25
|
if (isset($_SESSION['osC_Shipping_data']) === false) {
|
|
26
|
$_SESSION['osC_Shipping_data'] = array('shipping_boxes' => 1,
|
|
27
|
'shipping_weight' => 0,
|
|
28
|
'quotes' => array());
|
|
29
|
}
|
hpdl
|
1
|
30
|
|
hpdl
|
421
|
31
|
$this->_shipping_boxes =& $_SESSION['osC_Shipping_data']['shipping_boxes'];
|
|
32
|
$this->_shipping_weight =& $_SESSION['osC_Shipping_data']['shipping_weight'];
|
|
33
|
$this->_quotes =& $_SESSION['osC_Shipping_data']['quotes'];
|
|
34
|
|
hpdl
|
425
|
35
|
$Qmodules = $osC_Database->query('select code from :table_templates_boxes where modules_group = "shipping"');
|
|
36
|
$Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
|
|
37
|
$Qmodules->setCache('modules-shipping');
|
|
38
|
$Qmodules->execute();
|
hpdl
|
421
|
39
|
|
hpdl
|
425
|
40
|
while ($Qmodules->next()) {
|
|
41
|
$this->_modules[] = $Qmodules->value('code');
|
|
42
|
}
|
|
43
|
|
|
44
|
$Qmodules->freeResult();
|
|
45
|
|
|
46
|
if (empty($this->_modules) === false) {
|
|
47
|
if ((empty($module) === false) && in_array(substr($module['id'], 0, strpos($module['id'], '_')), $this->_modules)) {
|
hpdl
|
427
|
48
|
$this->_modules = array($module['id']);
|
hpdl
|
1
|
49
|
}
|
|
50
|
|
hpdl
|
404
|
51
|
$osC_Language->load('modules-shipping');
|
|
52
|
|
hpdl
|
427
|
53
|
foreach ($this->_modules as $module) {
|
|
54
|
include('includes/modules/shipping/' . $module . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
|
hpdl
|
1
|
55
|
|
hpdl
|
427
|
56
|
$module_class = 'osC_Shipping_' . $module;
|
|
57
|
|
|
58
|
$GLOBALS[$module_class] = new $module_class();
|
|
59
|
$GLOBALS[$module_class]->initialize();
|
hpdl
|
1
|
60
|
}
|
hpdl
|
427
|
61
|
|
|
62
|
usort($this->_modules, array('osC_Shipping', '_usortModules'));
|
hpdl
|
1
|
63
|
}
|
|
64
|
}
|
|
65
|
|
hpdl
|
432
|
66
|
// class methods
|
|
67
|
function getCode() {
|
|
68
|
return $this->_code;
|
|
69
|
}
|
|
70
|
|
|
71
|
function getTitle() {
|
|
72
|
return $this->_title;
|
|
73
|
}
|
|
74
|
|
|
75
|
function getDescription() {
|
|
76
|
return $this->_description;
|
|
77
|
}
|
|
78
|
|
|
79
|
function getStatus() {
|
|
80
|
return $this->_status;
|
|
81
|
}
|
|
82
|
|
|
83
|
function getSortOrder() {
|
|
84
|
return $this->_sort_order;
|
|
85
|
}
|
|
86
|
|
hpdl
|
425
|
87
|
function calculateQuotes() {
|
hpdl
|
421
|
88
|
global $osC_ShoppingCart;
|
hpdl
|
1
|
89
|
|
hpdl
|
421
|
90
|
$this->_quotes = array();
|
hpdl
|
1
|
91
|
|
hpdl
|
421
|
92
|
if (is_array($this->_modules)) {
|
|
93
|
$this->_shipping_weight = $osC_ShoppingCart->getWeight();
|
hpdl
|
1
|
94
|
|
hpdl
|
421
|
95
|
if (SHIPPING_BOX_WEIGHT >= ($this->_shipping_weight * SHIPPING_BOX_PADDING/100)) {
|
|
96
|
$this->_shipping_weight = $this->_shipping_weight + SHIPPING_BOX_WEIGHT;
|
hpdl
|
1
|
97
|
} else {
|
hpdl
|
421
|
98
|
$this->_shipping_weight = $this->_shipping_weight + ($this->_shipping_weight * SHIPPING_BOX_PADDING/100);
|
hpdl
|
1
|
99
|
}
|
|
100
|
|
hpdl
|
421
|
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;
|
hpdl
|
1
|
104
|
}
|
|
105
|
|
|
106
|
$include_quotes = array();
|
|
107
|
|
hpdl
|
432
|
108
|
if (defined('MODULE_SHIPPING_FREE_STATUS') && (MODULE_SHIPPING_FREE_STATUS == 'True') && ($GLOBALS['osC_Shipping_free']->getStatus() === true)) {
|
hpdl
|
422
|
109
|
$include_quotes[] = 'free';
|
|
110
|
} else {
|
hpdl
|
425
|
111
|
foreach ($this->_modules as $module) {
|
hpdl
|
432
|
112
|
if ($GLOBALS['osC_Shipping_' . $module]->getStatus() === true) {
|
hpdl
|
425
|
113
|
$include_quotes[] = 'osC_Shipping_' . $module;
|
hpdl
|
1
|
114
|
}
|
|
115
|
}
|
|
116
|
}
|
|
117
|
|
hpdl
|
421
|
118
|
foreach ($include_quotes as $module) {
|
hpdl
|
425
|
119
|
$quotes = $GLOBALS[$module]->quote();
|
hpdl
|
421
|
120
|
|
|
121
|
if (is_array($quotes)) {
|
|
122
|
$this->_quotes[] = $quotes;
|
|
123
|
}
|
hpdl
|
1
|
124
|
}
|
|
125
|
}
|
hpdl
|
421
|
126
|
}
|
hpdl
|
1
|
127
|
|
hpdl
|
421
|
128
|
function hasQuotes() {
|
|
129
|
return !empty($this->_quotes);
|
hpdl
|
1
|
130
|
}
|
|
131
|
|
hpdl
|
422
|
132
|
function numberOfQuotes() {
|
|
133
|
$total_quotes = 0;
|
|
134
|
|
|
135
|
foreach ($this->_quotes as $quotes) {
|
|
136
|
$total_quotes += sizeof($quotes['methods']);
|
|
137
|
}
|
|
138
|
|
|
139
|
return $total_quotes;
|
|
140
|
}
|
|
141
|
|
hpdl
|
425
|
142
|
function getQuotes($module = '') {
|
|
143
|
if (empty($module) === false) {
|
|
144
|
list($module, $method) = explode('_', $module);
|
|
145
|
|
hpdl
|
421
|
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,
|
hpdl
|
438
|
153
|
'tax_class_id' => $quote['tax_class_id']);
|
hpdl
|
421
|
154
|
}
|
|
155
|
}
|
|
156
|
}
|
|
157
|
}
|
|
158
|
}
|
|
159
|
|
|
160
|
return $this->_quotes;
|
|
161
|
}
|
|
162
|
|
|
163
|
function getCheapestQuote() {
|
|
164
|
if (is_array($this->_modules)) {
|
hpdl
|
1
|
165
|
$rates = array();
|
|
166
|
|
hpdl
|
421
|
167
|
foreach ($this->_modules as $value) {
|
hpdl
|
425
|
168
|
$class = 'osC_Shipping_' . $value;
|
hpdl
|
432
|
169
|
if ($GLOBALS[$class]->getStatus() === true) {
|
hpdl
|
1
|
170
|
$quotes = $GLOBALS[$class]->quotes;
|
hpdl
|
421
|
171
|
|
hpdl
|
1
|
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'] . ')',
|
hpdl
|
438
|
176
|
'cost' => $quotes['methods'][$i]['cost'],
|
|
177
|
'tax_class_id' => $quotes['tax_class_id']);
|
hpdl
|
1
|
178
|
}
|
|
179
|
}
|
|
180
|
}
|
|
181
|
}
|
|
182
|
|
|
183
|
$cheapest = false;
|
hpdl
|
421
|
184
|
|
hpdl
|
1
|
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];
|
|
192
|
}
|
|
193
|
}
|
|
194
|
|
|
195
|
return $cheapest;
|
|
196
|
}
|
|
197
|
}
|
hpdl
|
425
|
198
|
|
|
199
|
function hasActive() {
|
|
200
|
static $has_active;
|
|
201
|
|
|
202
|
if (isset($has_active) === false) {
|
|
203
|
$has_active = false;
|
|
204
|
|
|
205
|
foreach ($this->_modules as $module) {
|
hpdl
|
432
|
206
|
if ($GLOBALS['osC_Shipping_' . $module]->getStatus() === true) {
|
hpdl
|
425
|
207
|
$has_active = true;
|
|
208
|
break;
|
|
209
|
}
|
|
210
|
}
|
|
211
|
}
|
|
212
|
|
|
213
|
return $has_active;
|
|
214
|
}
|
|
215
|
|
|
216
|
function hasKeys() {
|
|
217
|
static $has_keys;
|
|
218
|
|
|
219
|
if (isset($has_keys) === false) {
|
|
220
|
$has_keys = (sizeof($this->getKeys()) > 0) ? true : false;
|
|
221
|
}
|
|
222
|
|
|
223
|
return $has_keys;
|
|
224
|
}
|
|
225
|
|
|
226
|
function install() {
|
|
227
|
global $osC_Database, $osC_Language;
|
|
228
|
|
|
229
|
$Qinstall = $osC_Database->query('insert into :table_templates_boxes (title, code, author_name, author_www, modules_group) values (:title, :code, :author_name, :author_www, :modules_group)');
|
|
230
|
$Qinstall->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
|
|
231
|
$Qinstall->bindValue(':title', $this->_title);
|
|
232
|
$Qinstall->bindValue(':code', $this->_code);
|
|
233
|
$Qinstall->bindValue(':author_name', $this->_author_name);
|
|
234
|
$Qinstall->bindValue(':author_www', $this->_author_www);
|
|
235
|
$Qinstall->bindValue(':modules_group', $this->_group);
|
|
236
|
$Qinstall->execute();
|
|
237
|
|
|
238
|
foreach ($osC_Language->getAll() as $key => $value) {
|
|
239
|
if (file_exists(dirname(__FILE__) . '/../languages/' . $key . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
|
|
240
|
foreach ($osC_Language->extractDefinitions($key . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
|
|
241
|
$Qcheck = $osC_Database->query('select id from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id limit 1');
|
|
242
|
$Qcheck->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
|
|
243
|
$Qcheck->bindValue(':definition_key', $def['key']);
|
|
244
|
$Qcheck->bindValue(':content_group', $def['group']);
|
|
245
|
$Qcheck->bindInt(':languages_id', $value['id']);
|
|
246
|
$Qcheck->execute();
|
|
247
|
|
|
248
|
if ($Qcheck->numberOfRows() === 1) {
|
|
249
|
$Qdef = $osC_Database->query('update :table_languages_definitions set definition_value = :definition_value where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id');
|
|
250
|
} else {
|
|
251
|
$Qdef = $osC_Database->query('insert into :table_languages_definitions (languages_id, content_group, definition_key, definition_value) values (:languages_id, :content_group, :definition_key, :definition_value)');
|
|
252
|
}
|
|
253
|
$Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
|
|
254
|
$Qdef->bindInt(':languages_id', $value['id']);
|
|
255
|
$Qdef->bindValue(':content_group', $def['group']);
|
|
256
|
$Qdef->bindValue(':definition_key', $def['key']);
|
|
257
|
$Qdef->bindValue(':definition_value', $def['value']);
|
|
258
|
$Qdef->execute();
|
|
259
|
}
|
|
260
|
}
|
|
261
|
}
|
|
262
|
|
|
263
|
osC_Cache::clear('languages');
|
|
264
|
}
|
|
265
|
|
|
266
|
function remove() {
|
|
267
|
global $osC_Database, $osC_Language;
|
|
268
|
|
|
269
|
$Qdel = $osC_Database->query('delete from :table_templates_boxes where code = :code and modules_group = :modules_group');
|
|
270
|
$Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
|
|
271
|
$Qdel->bindValue(':code', $this->_code);
|
|
272
|
$Qdel->bindValue(':modules_group', $this->_group);
|
|
273
|
$Qdel->execute();
|
|
274
|
|
|
275
|
if ($this->hasKeys()) {
|
|
276
|
$Qdel = $osC_Database->query('delete from :table_configuration where configuration_key in (":configuration_key")');
|
|
277
|
$Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION);
|
|
278
|
$Qdel->bindRaw(':configuration_key', implode('", "', $this->getKeys()));
|
|
279
|
$Qdel->execute();
|
|
280
|
}
|
|
281
|
|
|
282
|
if (file_exists(dirname(__FILE__) . '/../languages/' . $osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
|
|
283
|
foreach ($osC_Language->extractDefinitions($osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
|
|
284
|
$Qdel = $osC_Database->query('delete from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group');
|
|
285
|
$Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
|
|
286
|
$Qdel->bindValue(':definition_key', $def['key']);
|
|
287
|
$Qdel->bindValue(':content_group', $def['group']);
|
|
288
|
$Qdel->execute();
|
|
289
|
}
|
|
290
|
|
|
291
|
osC_Cache::clear('languages');
|
|
292
|
}
|
|
293
|
}
|
hpdl
|
427
|
294
|
|
|
295
|
function _usortModules($a, $b) {
|
hpdl
|
432
|
296
|
if ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() == $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) {
|
|
297
|
return strnatcasecmp($GLOBALS['osC_Shipping_' . $a]->getTitle(), $GLOBALS['osC_Shipping_' . $a]->getTitle());
|
hpdl
|
427
|
298
|
}
|
|
299
|
|
hpdl
|
432
|
300
|
return ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() < $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) ? -1 : 1;
|
hpdl
|
427
|
301
|
}
|
hpdl
|
1
|
302
|
}
|
|
303
|
?>
|