hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
153
|
3
|
$Id: shipping.php 439 2006-02-19 16:33:18Z 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
|
$_keys,
|
|
18
|
$_group = 'shipping';
|
hpdl
|
1
|
19
|
|
|
20
|
// class constructor
|
hpdl
|
421
|
21
|
function osC_Shipping($module = '') {
|
hpdl
|
425
|
22
|
global $osC_Database, $osC_Language;
|
hpdl
|
377
|
23
|
|
hpdl
|
421
|
24
|
if (isset($_SESSION['osC_Shipping_data']) === false) {
|
hpdl
|
439
|
25
|
$_SESSION['osC_Shipping_data'] = array('quotes' => array(),
|
|
26
|
'cartID' => null);
|
hpdl
|
421
|
27
|
}
|
hpdl
|
1
|
28
|
|
hpdl
|
421
|
29
|
$this->_quotes =& $_SESSION['osC_Shipping_data']['quotes'];
|
hpdl
|
439
|
30
|
$this->_cartID =& $_SESSION['osC_Shipping_data']['cartID'];
|
hpdl
|
421
|
31
|
|
hpdl
|
425
|
32
|
$Qmodules = $osC_Database->query('select code from :table_templates_boxes where modules_group = "shipping"');
|
|
33
|
$Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
|
|
34
|
$Qmodules->setCache('modules-shipping');
|
|
35
|
$Qmodules->execute();
|
hpdl
|
421
|
36
|
|
hpdl
|
425
|
37
|
while ($Qmodules->next()) {
|
|
38
|
$this->_modules[] = $Qmodules->value('code');
|
|
39
|
}
|
|
40
|
|
|
41
|
$Qmodules->freeResult();
|
|
42
|
|
|
43
|
if (empty($this->_modules) === false) {
|
hpdl
|
439
|
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, '_')));
|
hpdl
|
1
|
47
|
}
|
|
48
|
|
hpdl
|
404
|
49
|
$osC_Language->load('modules-shipping');
|
|
50
|
|
hpdl
|
427
|
51
|
foreach ($this->_modules as $module) {
|
|
52
|
$module_class = 'osC_Shipping_' . $module;
|
|
53
|
|
hpdl
|
439
|
54
|
if (class_exists($module_class) === false) {
|
|
55
|
include('includes/modules/shipping/' . $module . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
|
|
56
|
}
|
|
57
|
|
hpdl
|
427
|
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
|
}
|
hpdl
|
439
|
64
|
|
|
65
|
$this->_calculate();
|
hpdl
|
1
|
66
|
}
|
|
67
|
|
hpdl
|
432
|
68
|
// class methods
|
|
69
|
function getCode() {
|
|
70
|
return $this->_code;
|
|
71
|
}
|
|
72
|
|
|
73
|
function getTitle() {
|
|
74
|
return $this->_title;
|
|
75
|
}
|
|
76
|
|
|
77
|
function getDescription() {
|
|
78
|
return $this->_description;
|
|
79
|
}
|
|
80
|
|
|
81
|
function getStatus() {
|
|
82
|
return $this->_status;
|
|
83
|
}
|
|
84
|
|
|
85
|
function getSortOrder() {
|
|
86
|
return $this->_sort_order;
|
|
87
|
}
|
|
88
|
|
hpdl
|
421
|
89
|
function hasQuotes() {
|
|
90
|
return !empty($this->_quotes);
|
hpdl
|
1
|
91
|
}
|
|
92
|
|
hpdl
|
422
|
93
|
function numberOfQuotes() {
|
|
94
|
$total_quotes = 0;
|
|
95
|
|
|
96
|
foreach ($this->_quotes as $quotes) {
|
|
97
|
$total_quotes += sizeof($quotes['methods']);
|
|
98
|
}
|
|
99
|
|
|
100
|
return $total_quotes;
|
|
101
|
}
|
|
102
|
|
hpdl
|
439
|
103
|
function getQuotes() {
|
|
104
|
return $this->_quotes;
|
|
105
|
}
|
hpdl
|
425
|
106
|
|
hpdl
|
439
|
107
|
function getQuote($module = '') {
|
|
108
|
if (empty($module)) {
|
|
109
|
$module = $this->_selected_module;
|
hpdl
|
421
|
110
|
}
|
|
111
|
|
hpdl
|
439
|
112
|
list($module_id, $method_id) = explode('_', $module);
|
hpdl
|
421
|
113
|
|
hpdl
|
439
|
114
|
$rate = array();
|
hpdl
|
1
|
115
|
|
hpdl
|
439
|
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']);
|
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'],
|
|
144
|
'is_cheapest' => true);
|
hpdl
|
1
|
145
|
}
|
|
146
|
}
|
|
147
|
}
|
hpdl
|
439
|
148
|
|
|
149
|
return $rate;
|
hpdl
|
1
|
150
|
}
|
hpdl
|
425
|
151
|
|
|
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
|
432
|
159
|
if ($GLOBALS['osC_Shipping_' . $module]->getStatus() === true) {
|
hpdl
|
425
|
160
|
$has_active = true;
|
|
161
|
break;
|
|
162
|
}
|
|
163
|
}
|
|
164
|
}
|
|
165
|
|
|
166
|
return $has_active;
|
|
167
|
}
|
|
168
|
|
|
169
|
function hasKeys() {
|
|
170
|
static $has_keys;
|
|
171
|
|
|
172
|
if (isset($has_keys) === false) {
|
|
173
|
$has_keys = (sizeof($this->getKeys()) > 0) ? true : false;
|
|
174
|
}
|
|
175
|
|
|
176
|
return $has_keys;
|
|
177
|
}
|
|
178
|
|
|
179
|
function install() {
|
|
180
|
global $osC_Database, $osC_Language;
|
|
181
|
|
|
182
|
$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)');
|
|
183
|
$Qinstall->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
|
|
184
|
$Qinstall->bindValue(':title', $this->_title);
|
|
185
|
$Qinstall->bindValue(':code', $this->_code);
|
|
186
|
$Qinstall->bindValue(':author_name', $this->_author_name);
|
|
187
|
$Qinstall->bindValue(':author_www', $this->_author_www);
|
|
188
|
$Qinstall->bindValue(':modules_group', $this->_group);
|
|
189
|
$Qinstall->execute();
|
|
190
|
|
|
191
|
foreach ($osC_Language->getAll() as $key => $value) {
|
|
192
|
if (file_exists(dirname(__FILE__) . '/../languages/' . $key . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
|
|
193
|
foreach ($osC_Language->extractDefinitions($key . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
|
|
194
|
$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');
|
|
195
|
$Qcheck->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
|
|
196
|
$Qcheck->bindValue(':definition_key', $def['key']);
|
|
197
|
$Qcheck->bindValue(':content_group', $def['group']);
|
|
198
|
$Qcheck->bindInt(':languages_id', $value['id']);
|
|
199
|
$Qcheck->execute();
|
|
200
|
|
|
201
|
if ($Qcheck->numberOfRows() === 1) {
|
|
202
|
$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');
|
|
203
|
} else {
|
|
204
|
$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)');
|
|
205
|
}
|
|
206
|
$Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
|
|
207
|
$Qdef->bindInt(':languages_id', $value['id']);
|
|
208
|
$Qdef->bindValue(':content_group', $def['group']);
|
|
209
|
$Qdef->bindValue(':definition_key', $def['key']);
|
|
210
|
$Qdef->bindValue(':definition_value', $def['value']);
|
|
211
|
$Qdef->execute();
|
|
212
|
}
|
|
213
|
}
|
|
214
|
}
|
|
215
|
|
|
216
|
osC_Cache::clear('languages');
|
|
217
|
}
|
|
218
|
|
|
219
|
function remove() {
|
|
220
|
global $osC_Database, $osC_Language;
|
|
221
|
|
|
222
|
$Qdel = $osC_Database->query('delete from :table_templates_boxes where code = :code and modules_group = :modules_group');
|
|
223
|
$Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
|
|
224
|
$Qdel->bindValue(':code', $this->_code);
|
|
225
|
$Qdel->bindValue(':modules_group', $this->_group);
|
|
226
|
$Qdel->execute();
|
|
227
|
|
|
228
|
if ($this->hasKeys()) {
|
|
229
|
$Qdel = $osC_Database->query('delete from :table_configuration where configuration_key in (":configuration_key")');
|
|
230
|
$Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION);
|
|
231
|
$Qdel->bindRaw(':configuration_key', implode('", "', $this->getKeys()));
|
|
232
|
$Qdel->execute();
|
|
233
|
}
|
|
234
|
|
|
235
|
if (file_exists(dirname(__FILE__) . '/../languages/' . $osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
|
|
236
|
foreach ($osC_Language->extractDefinitions($osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
|
|
237
|
$Qdel = $osC_Database->query('delete from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group');
|
|
238
|
$Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
|
|
239
|
$Qdel->bindValue(':definition_key', $def['key']);
|
|
240
|
$Qdel->bindValue(':content_group', $def['group']);
|
|
241
|
$Qdel->execute();
|
|
242
|
}
|
|
243
|
|
|
244
|
osC_Cache::clear('languages');
|
|
245
|
}
|
|
246
|
}
|
hpdl
|
427
|
247
|
|
hpdl
|
439
|
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
|
|
hpdl
|
427
|
280
|
function _usortModules($a, $b) {
|
hpdl
|
432
|
281
|
if ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() == $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) {
|
|
282
|
return strnatcasecmp($GLOBALS['osC_Shipping_' . $a]->getTitle(), $GLOBALS['osC_Shipping_' . $a]->getTitle());
|
hpdl
|
427
|
283
|
}
|
|
284
|
|
hpdl
|
432
|
285
|
return ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() < $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) ? -1 : 1;
|
hpdl
|
427
|
286
|
}
|
hpdl
|
1
|
287
|
}
|
|
288
|
?>
|