1
|
<?php
|
2
|
/* --------------------------------------------------------------
|
3
|
shipping.php 2013-11-26 gm
|
4
|
Gambio GmbH
|
5
|
http://www.gambio.de
|
6
|
Copyright (c) 2013 Gambio GmbH
|
7
|
Released under the GNU General Public License (Version 2)
|
8
|
[http://www.gnu.org/licenses/gpl-2.0.html]
|
9
|
--------------------------------------------------------------
|
10
|
|
11
|
|
12
|
based on:
|
13
|
(c) 2000-2001 The Exchange Project (earlier name of osCommerce)
|
14
|
(c) 2002-2003 osCommerce(shipping.php,v 1.22 2003/05/08); www.oscommerce.com
|
15
|
(c) 2003 nextcommerce (shipping.php,v 1.9 2003/08/17); www.nextcommerce.org
|
16
|
(c) 2003 XT-Commerce - community made shopping http://www.xt-commerce.com ($Id: shipping.php 1305 2005-10-14 10:30:03Z mz $)
|
17
|
|
18
|
Released under the GNU General Public License
|
19
|
---------------------------------------------------------------------------------------*/
|
20
|
|
21
|
require_once(DIR_FS_INC . 'xtc_in_array.inc.php');
|
22
|
if (!class_exists('shipping_ORIGIN', false))
|
23
|
{
|
24
|
class shipping_ORIGIN {
|
25
|
var $modules;
|
26
|
|
27
|
// class constructor
|
28
|
function shipping_ORIGIN($module = '') {
|
29
|
global $PHP_SELF, $order;
|
30
|
|
31
|
if (empty($order))
|
32
|
{
|
33
|
if ($_SESSION['cart']->count_contents_virtual() > 0) { // cart contains products that are NOT virtual
|
34
|
if (!isset ($_SESSION['sendto'])) {
|
35
|
$_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
|
36
|
} else {
|
37
|
// verify the selected shipping address
|
38
|
$check_address_query = xtc_db_query("select count(*) as total from ".TABLE_ADDRESS_BOOK." where customers_id = '".(int) $_SESSION['customer_id']."' and address_book_id = '".(int) $_SESSION['sendto']."'");
|
39
|
$check_address = xtc_db_fetch_array($check_address_query);
|
40
|
|
41
|
if ($check_address['total'] != '1') {
|
42
|
$_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
|
43
|
if (isset ($_SESSION['shipping']))
|
44
|
unset ($_SESSION['shipping']);
|
45
|
}
|
46
|
}
|
47
|
}
|
48
|
|
49
|
$order = new order();
|
50
|
|
51
|
$coo_cart_shipping_costs_control = MainFactory::create_object('CartShippingCostsControl', array(), true);
|
52
|
$t_country_array = $coo_cart_shipping_costs_control->get_selected_country();
|
53
|
$t_country = xtc_get_countriesList( key($t_country_array), true, true );
|
54
|
|
55
|
$order->delivery['country']['id'] = key($t_country_array);
|
56
|
$order->delivery['country']['iso_code_2'] = $t_country['countries_iso_code_2'];
|
57
|
}
|
58
|
|
59
|
if (defined('MODULE_SHIPPING_INSTALLED') && xtc_not_null(MODULE_SHIPPING_INSTALLED)) {
|
60
|
$this->modules = explode(';', MODULE_SHIPPING_INSTALLED);
|
61
|
|
62
|
$include_modules = array();
|
63
|
|
64
|
if ( (xtc_not_null($module)) && (in_array(substr($module['id'], 0, strpos($module['id'], '_')) . '.php', $this->modules)) ) {
|
65
|
$include_modules[] = array('class' => substr($module['id'], 0, strpos($module['id'], '_')), 'file' => substr($module['id'], 0, strpos($module['id'], '_')) . '.php');
|
66
|
} else {
|
67
|
reset($this->modules);
|
68
|
while (list(, $value) = each($this->modules)) {
|
69
|
$class = substr($value, 0, strrpos($value, '.'));
|
70
|
$include_modules[] = array('class' => $class, 'file' => $value);
|
71
|
}
|
72
|
}
|
73
|
// load unallowed modules into array
|
74
|
$unallowed_modules = explode(',',$_SESSION['customers_status']['customers_status_shipping_unallowed'].','.$order->customer['shipping_unallowed']);
|
75
|
for ($i = 0, $n = sizeof($include_modules); $i < $n; $i++) {
|
76
|
if (xtc_in_array(str_replace('.php', '', $include_modules[$i]['file']), $unallowed_modules) != 'false') {
|
77
|
// check if zone is alowed to see module
|
78
|
$t_allowed = trim(constant(MODULE_SHIPPING_ . strtoupper(str_replace('.php', '', $include_modules[$i]['file'])) . _ALLOWED));
|
79
|
if ($t_allowed != '') {
|
80
|
|
81
|
if(strpos($t_allowed, ',') !== false)
|
82
|
{
|
83
|
$allowed_zones = explode(',', $t_allowed);
|
84
|
}
|
85
|
else
|
86
|
{
|
87
|
$allowed_zones = array($t_allowed);
|
88
|
}
|
89
|
|
90
|
} else {
|
91
|
$allowed_zones = array();
|
92
|
}
|
93
|
|
94
|
if (in_array($_SESSION['delivery_zone'], $allowed_zones) == true || count($allowed_zones) == 0) {
|
95
|
include_once(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/shipping/' . $include_modules[$i]['file']);
|
96
|
include_once(DIR_WS_MODULES . 'shipping/' . $include_modules[$i]['file']);
|
97
|
|
98
|
$GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
|
99
|
}
|
100
|
}
|
101
|
}
|
102
|
}
|
103
|
}
|
104
|
|
105
|
function quote($method = '', $module = '') {
|
106
|
global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;
|
107
|
|
108
|
$quotes_array = array();
|
109
|
|
110
|
if (is_array($this->modules)) {
|
111
|
$shipping_quoted = '';
|
112
|
$shipping_num_boxes = 1;
|
113
|
$shipping_weight = $total_weight;
|
114
|
|
115
|
if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) {
|
116
|
$shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT;
|
117
|
} else {
|
118
|
$shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100);
|
119
|
}
|
120
|
|
121
|
if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
|
122
|
$shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
|
123
|
$shipping_weight = $shipping_weight/$shipping_num_boxes;
|
124
|
}
|
125
|
|
126
|
$include_quotes = array();
|
127
|
|
128
|
reset($this->modules);
|
129
|
while (list(, $value) = each($this->modules)) {
|
130
|
$class = substr($value, 0, strrpos($value, '.'));
|
131
|
if (xtc_not_null($module)) {
|
132
|
if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) {
|
133
|
$include_quotes[] = $class;
|
134
|
}
|
135
|
} elseif ($GLOBALS[$class]->enabled) {
|
136
|
$include_quotes[] = $class;
|
137
|
}
|
138
|
}
|
139
|
|
140
|
$size = sizeof($include_quotes);
|
141
|
for ($i=0; $i<$size; $i++) {
|
142
|
$quotes = $GLOBALS[$include_quotes[$i]]->quote($method);
|
143
|
if (is_array($quotes)) $quotes_array[] = $quotes;
|
144
|
}
|
145
|
}
|
146
|
|
147
|
return $quotes_array;
|
148
|
}
|
149
|
|
150
|
function cheapest() {
|
151
|
|
152
|
if (is_array($this->modules)) {
|
153
|
$rates = array();
|
154
|
|
155
|
reset($this->modules);
|
156
|
while (list(, $value) = each($this->modules)) {
|
157
|
$class = substr($value, 0, strrpos($value, '.'));
|
158
|
// BOF GM_MOD:
|
159
|
if ($GLOBALS[$class]->enabled && $class != 'selfpickup') {
|
160
|
$quotes = $GLOBALS[$class]->quotes;
|
161
|
$size = sizeof($quotes['methods']);
|
162
|
for ($i=0; $i<$size; $i++) {
|
163
|
if(array_key_exists("cost",$quotes['methods'][$i])) {
|
164
|
$rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
|
165
|
'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')',
|
166
|
'cost' => $quotes['methods'][$i]['cost']);
|
167
|
// echo $quotes['methods'][$i]['cost'];
|
168
|
|
169
|
}
|
170
|
}
|
171
|
}
|
172
|
}
|
173
|
|
174
|
$cheapest = false;
|
175
|
$size = sizeof($rates);
|
176
|
for ($i=0; $i<$size; $i++) {
|
177
|
if (is_array($cheapest)) {
|
178
|
if ($rates[$i]['cost'] < $cheapest['cost']) {
|
179
|
$cheapest = $rates[$i];
|
180
|
}
|
181
|
} else {
|
182
|
$cheapest = $rates[$i];
|
183
|
}
|
184
|
}
|
185
|
return $cheapest;
|
186
|
|
187
|
}
|
188
|
|
189
|
}
|
190
|
|
191
|
function shopping_cart_cheapest()
|
192
|
{
|
193
|
$t_cheapest_shipping_module = false;
|
194
|
global $PHP_SELF, $order;
|
195
|
|
196
|
if (empty($order))
|
197
|
{
|
198
|
if (!isset ($_SESSION['sendto'])) {
|
199
|
$_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
|
200
|
} else {
|
201
|
// verify the selected shipping address
|
202
|
$check_address_query = xtc_db_query("select count(*) as total from ".TABLE_ADDRESS_BOOK." where customers_id = '".(int) $_SESSION['customer_id']."' and address_book_id = '".(int) $_SESSION['sendto']."'");
|
203
|
$check_address = xtc_db_fetch_array($check_address_query);
|
204
|
|
205
|
if ($check_address['total'] != '1') {
|
206
|
$_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
|
207
|
if (isset ($_SESSION['shipping']))
|
208
|
unset ($_SESSION['shipping']);
|
209
|
}
|
210
|
}
|
211
|
|
212
|
if ($order->content_type == 'virtual' || ($order->content_type == 'virtual_weight') || ($_SESSION['cart']->count_contents_virtual() == 0)) { // GV Code added
|
213
|
$_SESSION['shipping'] = false;
|
214
|
$_SESSION['sendto'] = false;
|
215
|
|
216
|
return $t_cheapest_shipping_module;
|
217
|
}
|
218
|
|
219
|
$order = new order();
|
220
|
}
|
221
|
|
222
|
if($this->is_shipping_free() === true)
|
223
|
{
|
224
|
if (file_exists(DIR_FS_CATALOG . 'lang/' . $_SESSION['language'] . '/modules/order_total/ot_shipping.php'))
|
225
|
{
|
226
|
require_once(DIR_FS_CATALOG . 'lang/' . $_SESSION['language'] . '/modules/order_total/ot_shipping.php');
|
227
|
}
|
228
|
$coo_cart_shipping_costs_control = MainFactory::create_object('CartShippingCostsControl', array(), true);
|
229
|
$_SESSION['cart_shipping_module'] = 'free';
|
230
|
$_SESSION['cart_shipping_method'] = 'free';
|
231
|
$t_cheapest_shipping_module = array('id' => 'free' . $coo_cart_shipping_costs_control->v_module_method_separator . 'free',
|
232
|
'module' => 'free',
|
233
|
'method_id' => 'free',
|
234
|
'method_title' => FREE_SHIPPING_TITLE,
|
235
|
'cost' => 0);
|
236
|
return $t_cheapest_shipping_module;
|
237
|
}
|
238
|
|
239
|
if (is_array($this->modules))
|
240
|
{
|
241
|
$unallowed_modules = explode(',',$_SESSION['customers_status']['customers_status_shipping_unallowed'].','.$order->customer['shipping_unallowed']);
|
242
|
$t_shipping_costs_array = $this->quote();
|
243
|
|
244
|
foreach ($t_shipping_costs_array as $t_module)
|
245
|
{
|
246
|
if (in_array($t_module['id'], $unallowed_modules))
|
247
|
{
|
248
|
continue;
|
249
|
}
|
250
|
|
251
|
if (constant(MODULE_SHIPPING_ . strtoupper($t_module['id']) . _ALLOWED) != '')
|
252
|
{
|
253
|
$t_allowed_zones = explode(',', constant(MODULE_SHIPPING_ . strtoupper($t_module['id']) . _ALLOWED));
|
254
|
}
|
255
|
else
|
256
|
{
|
257
|
$t_allowed_zones = array();
|
258
|
}
|
259
|
|
260
|
if (in_array($_SESSION['delivery_zone'], $t_allowed_zones) == false && count($t_allowed_zones) > 0 || isset($t_module['error']))
|
261
|
{
|
262
|
continue;
|
263
|
}
|
264
|
|
265
|
foreach ($t_module['methods'] as $t_method)
|
266
|
{
|
267
|
if ($t_cheapest_shipping_module === false
|
268
|
|| ((double)$t_method['cost'] < $t_cheapest_shipping_module['cost'] && $t_method['id'] != 'selfpickup')
|
269
|
|| $t_cheapest_shipping_module['id'] == 'selfpickup')
|
270
|
{
|
271
|
$t_cheapest_shipping_module = array('id' => $t_module['id'],
|
272
|
'module' => $t_module['module'],
|
273
|
'method_id' => $t_method['id'],
|
274
|
'method_title' => $t_method['title'],
|
275
|
'cost' => (double)$t_method['cost']);
|
276
|
}
|
277
|
}
|
278
|
}
|
279
|
}
|
280
|
|
281
|
return $t_cheapest_shipping_module;
|
282
|
}
|
283
|
|
284
|
function is_shipping_free($p_selected_country = false)
|
285
|
{
|
286
|
if ($_SESSION['cart']->count_contents_virtual() == 0)
|
287
|
{
|
288
|
return true;
|
289
|
}
|
290
|
|
291
|
if($p_selected_country !== false)
|
292
|
{
|
293
|
$t_selected_country = $p_selected_country;
|
294
|
}
|
295
|
else
|
296
|
{
|
297
|
$coo_cart_shipping_costs_control = MainFactory::create_object('CartShippingCostsControl', array(), true);
|
298
|
$t_selected_country = key($coo_cart_shipping_costs_control->get_selected_country());
|
299
|
}
|
300
|
|
301
|
if ((MODULE_ORDER_TOTAL_SHIPPING_DESTINATION == 'national' && STORE_COUNTRY == $t_selected_country) ||
|
302
|
(MODULE_ORDER_TOTAL_SHIPPING_DESTINATION == 'international' && STORE_COUNTRY != $t_selected_country) ||
|
303
|
(MODULE_ORDER_TOTAL_SHIPPING_DESTINATION == 'both'))
|
304
|
{
|
305
|
if (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true' && $_SESSION['cart']->total >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)
|
306
|
{
|
307
|
return true;
|
308
|
}
|
309
|
}
|
310
|
|
311
|
return false;
|
312
|
}
|
313
|
|
314
|
function module_is_allowed($p_country = false, $p_module = false)
|
315
|
{
|
316
|
if (empty($p_country) || empty($p_module) || $this->is_shipping_free() === true )
|
317
|
{
|
318
|
return false;
|
319
|
}
|
320
|
|
321
|
if (is_array($this->modules))
|
322
|
{
|
323
|
$t_shipping_modules_array = $this->quote();
|
324
|
|
325
|
foreach ($t_shipping_modules_array as $t_module)
|
326
|
{
|
327
|
if ($t_module['id'] == $p_module)
|
328
|
{
|
329
|
if (constant(MODULE_SHIPPING_ . strtoupper($t_module['id']) . _ALLOWED) != '')
|
330
|
{
|
331
|
$t_allowed_zones = explode(',', constant(MODULE_SHIPPING_ . strtoupper($t_module['id']) . _ALLOWED));
|
332
|
}
|
333
|
else
|
334
|
{
|
335
|
$t_allowed_zones = array();
|
336
|
}
|
337
|
|
338
|
$t_country_data = xtc_get_countriesList( $p_country, true, true );
|
339
|
|
340
|
if (!isset($t_module['error']) && (in_array($t_country_data['countries_iso_code_2'], $t_allowed_zones) == true || count($t_allowed_zones) == 0))
|
341
|
{
|
342
|
return true;
|
343
|
}
|
344
|
|
345
|
return false;
|
346
|
}
|
347
|
}
|
348
|
}
|
349
|
return false;
|
350
|
}
|
351
|
}
|
352
|
}
|