hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
153
|
3
|
$Id: shipping.php 422 2006-02-09 13:36:08Z 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,
|
|
17
|
$_shipping_weight = 0;
|
hpdl
|
1
|
18
|
|
|
19
|
// class constructor
|
hpdl
|
421
|
20
|
function osC_Shipping($module = '') {
|
hpdl
|
377
|
21
|
global $osC_Language;
|
|
22
|
|
hpdl
|
421
|
23
|
if (isset($_SESSION['osC_Shipping_data']) === false) {
|
|
24
|
$_SESSION['osC_Shipping_data'] = array('shipping_boxes' => 1,
|
|
25
|
'shipping_weight' => 0,
|
|
26
|
'quotes' => array());
|
|
27
|
}
|
hpdl
|
1
|
28
|
|
hpdl
|
421
|
29
|
$this->_shipping_boxes =& $_SESSION['osC_Shipping_data']['shipping_boxes'];
|
|
30
|
$this->_shipping_weight =& $_SESSION['osC_Shipping_data']['shipping_weight'];
|
|
31
|
$this->_quotes =& $_SESSION['osC_Shipping_data']['quotes'];
|
|
32
|
|
|
33
|
if (defined('MODULE_SHIPPING_INSTALLED') && (osc_empty(MODULE_SHIPPING_INSTALLED) === false)) {
|
|
34
|
$this->_modules = explode(';', MODULE_SHIPPING_INSTALLED);
|
|
35
|
|
hpdl
|
1
|
36
|
$include_modules = array();
|
|
37
|
|
hpdl
|
421
|
38
|
if ( (empty($module) === false) && (in_array(substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($_SERVER['PHP_SELF'], (strrpos($_SERVER['PHP_SELF'], '.')+1)), $this->_modules)) ) {
|
hpdl
|
1
|
39
|
$include_modules[] = array('class' => substr($module['id'], 0, strpos($module['id'], '_')), 'file' => substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($_SERVER['PHP_SELF'], (strrpos($_SERVER['PHP_SELF'], '.')+1)));
|
|
40
|
} else {
|
hpdl
|
421
|
41
|
foreach ($this->_modules as $value) {
|
hpdl
|
1
|
42
|
$class = substr($value, 0, strrpos($value, '.'));
|
|
43
|
$include_modules[] = array('class' => $class, 'file' => $value);
|
|
44
|
}
|
|
45
|
}
|
|
46
|
|
hpdl
|
404
|
47
|
$osC_Language->load('modules-shipping');
|
|
48
|
|
hpdl
|
421
|
49
|
foreach ($include_modules as $module) {
|
|
50
|
include('includes/modules/shipping/' . $module['file']);
|
hpdl
|
1
|
51
|
|
hpdl
|
421
|
52
|
$GLOBALS[$module['class']] = new $module['class'];
|
hpdl
|
422
|
53
|
$GLOBALS[$module['class']]->prepare();
|
hpdl
|
1
|
54
|
}
|
|
55
|
}
|
|
56
|
}
|
|
57
|
|
hpdl
|
421
|
58
|
function calculateQuotes($method = '', $module = '') {
|
|
59
|
global $osC_ShoppingCart;
|
hpdl
|
1
|
60
|
|
hpdl
|
421
|
61
|
$this->_quotes = array();
|
hpdl
|
1
|
62
|
|
hpdl
|
421
|
63
|
if (is_array($this->_modules)) {
|
|
64
|
$this->_shipping_weight = $osC_ShoppingCart->getWeight();
|
hpdl
|
1
|
65
|
|
hpdl
|
421
|
66
|
if (SHIPPING_BOX_WEIGHT >= ($this->_shipping_weight * SHIPPING_BOX_PADDING/100)) {
|
|
67
|
$this->_shipping_weight = $this->_shipping_weight + SHIPPING_BOX_WEIGHT;
|
hpdl
|
1
|
68
|
} else {
|
hpdl
|
421
|
69
|
$this->_shipping_weight = $this->_shipping_weight + ($this->_shipping_weight * SHIPPING_BOX_PADDING/100);
|
hpdl
|
1
|
70
|
}
|
|
71
|
|
hpdl
|
421
|
72
|
if ($this->_shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
|
|
73
|
$this->_shipping_boxes = ceil($this->_shipping_weight / SHIPPING_MAX_WEIGHT);
|
|
74
|
$this->_shipping_weight = $this->_shipping_weight / $this->_shipping_boxes;
|
hpdl
|
1
|
75
|
}
|
|
76
|
|
|
77
|
$include_quotes = array();
|
|
78
|
|
hpdl
|
422
|
79
|
if (defined('MODULE_SHIPPING_FREE_STATUS') && (MODULE_SHIPPING_FREE_STATUS == 'True') && ($GLOBALS['free']->enabled)) {
|
|
80
|
$include_quotes[] = 'free';
|
|
81
|
} else {
|
|
82
|
foreach ($this->_modules as $value) {
|
|
83
|
$class = substr($value, 0, strrpos($value, '.'));
|
|
84
|
|
|
85
|
if (tep_not_null($module)) {
|
|
86
|
if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) {
|
|
87
|
$include_quotes[] = $class;
|
|
88
|
}
|
|
89
|
} elseif ($GLOBALS[$class]->enabled) {
|
hpdl
|
1
|
90
|
$include_quotes[] = $class;
|
|
91
|
}
|
|
92
|
}
|
|
93
|
}
|
|
94
|
|
hpdl
|
421
|
95
|
foreach ($include_quotes as $module) {
|
|
96
|
$quotes = $GLOBALS[$module]->quote($method);
|
|
97
|
|
|
98
|
if (is_array($quotes)) {
|
|
99
|
$this->_quotes[] = $quotes;
|
|
100
|
}
|
hpdl
|
1
|
101
|
}
|
|
102
|
}
|
hpdl
|
421
|
103
|
}
|
hpdl
|
1
|
104
|
|
hpdl
|
421
|
105
|
function hasQuotes() {
|
|
106
|
return !empty($this->_quotes);
|
hpdl
|
1
|
107
|
}
|
|
108
|
|
hpdl
|
422
|
109
|
function numberOfQuotes() {
|
|
110
|
$total_quotes = 0;
|
|
111
|
|
|
112
|
foreach ($this->_quotes as $quotes) {
|
|
113
|
$total_quotes += sizeof($quotes['methods']);
|
|
114
|
}
|
|
115
|
|
|
116
|
return $total_quotes;
|
|
117
|
}
|
|
118
|
|
hpdl
|
421
|
119
|
function getQuotes($method = '', $module = '') {
|
|
120
|
if ( (empty($method) === false) && (empty($module) === false) ) {
|
|
121
|
foreach ($this->_quotes as $quote) {
|
|
122
|
if ($quote['id'] == $module) {
|
|
123
|
foreach ($quote['methods'] as $quote_method) {
|
|
124
|
if ($quote_method['id'] == $method) {
|
|
125
|
return array('id' => $quote['id'],
|
|
126
|
'module' => $quote['module'],
|
|
127
|
'methods' => $quote_method,
|
|
128
|
'tax' => $quote['tax']);
|
|
129
|
}
|
|
130
|
}
|
|
131
|
}
|
|
132
|
}
|
|
133
|
}
|
|
134
|
|
|
135
|
return $this->_quotes;
|
|
136
|
}
|
|
137
|
|
|
138
|
function getCheapestQuote() {
|
|
139
|
if (is_array($this->_modules)) {
|
hpdl
|
1
|
140
|
$rates = array();
|
|
141
|
|
hpdl
|
421
|
142
|
foreach ($this->_modules as $value) {
|
hpdl
|
1
|
143
|
$class = substr($value, 0, strrpos($value, '.'));
|
|
144
|
if ($GLOBALS[$class]->enabled) {
|
|
145
|
$quotes = $GLOBALS[$class]->quotes;
|
hpdl
|
421
|
146
|
|
hpdl
|
1
|
147
|
for ($i=0, $n=sizeof($quotes['methods']); $i<$n; $i++) {
|
|
148
|
if (isset($quotes['methods'][$i]['cost']) && tep_not_null($quotes['methods'][$i]['cost'])) {
|
|
149
|
$rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
|
|
150
|
'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')',
|
|
151
|
'cost' => $quotes['methods'][$i]['cost']);
|
|
152
|
}
|
|
153
|
}
|
|
154
|
}
|
|
155
|
}
|
|
156
|
|
|
157
|
$cheapest = false;
|
hpdl
|
421
|
158
|
|
hpdl
|
1
|
159
|
for ($i=0, $n=sizeof($rates); $i<$n; $i++) {
|
|
160
|
if (is_array($cheapest)) {
|
|
161
|
if ($rates[$i]['cost'] < $cheapest['cost']) {
|
|
162
|
$cheapest = $rates[$i];
|
|
163
|
}
|
|
164
|
} else {
|
|
165
|
$cheapest = $rates[$i];
|
|
166
|
}
|
|
167
|
}
|
|
168
|
|
|
169
|
return $cheapest;
|
|
170
|
}
|
|
171
|
}
|
|
172
|
}
|
|
173
|
?>
|