hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
19
|
3
|
$Id: shopping_cart.php 826 2006-08-29 11:39:48Z hpdl $
|
hpdl
|
1
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
hpdl
|
418
|
8
|
Copyright (c) 2006 osCommerce
|
hpdl
|
1
|
9
|
|
|
10
|
Released under the GNU General Public License
|
|
11
|
*/
|
|
12
|
|
hpdl
|
418
|
13
|
class osC_ShoppingCart {
|
hpdl
|
420
|
14
|
var $_contents = array(),
|
hpdl
|
435
|
15
|
$_sub_total = 0,
|
hpdl
|
420
|
16
|
$_total = 0,
|
|
17
|
$_weight = 0,
|
hpdl
|
421
|
18
|
$_tax = 0,
|
hpdl
|
435
|
19
|
$_tax_groups = array(),
|
hpdl
|
420
|
20
|
$_cartID,
|
|
21
|
$_content_type,
|
|
22
|
$_products_in_stock = true;
|
hpdl
|
1
|
23
|
|
hpdl
|
418
|
24
|
function osC_ShoppingCart() {
|
hpdl
|
809
|
25
|
if (!isset($_SESSION['osC_ShoppingCart_data'])) {
|
hpdl
|
418
|
26
|
$_SESSION['osC_ShoppingCart_data'] = array('contents' => array(),
|
hpdl
|
435
|
27
|
'sub_total_cost' => 0,
|
hpdl
|
419
|
28
|
'total_cost' => 0,
|
|
29
|
'total_weight' => 0,
|
hpdl
|
435
|
30
|
'tax' => 0,
|
|
31
|
'tax_groups' => array(),
|
hpdl
|
439
|
32
|
'shipping_boxes_weight' => 0,
|
|
33
|
'shipping_boxes' => 1,
|
|
34
|
'cart_id' => $this->generateCartID(),
|
|
35
|
'shipping_address' => array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY),
|
hpdl
|
421
|
36
|
'shipping_method' => array(),
|
hpdl
|
439
|
37
|
'billing_address' => array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY),
|
|
38
|
'billing_method' => array(),
|
|
39
|
'order_totals' => array());
|
hpdl
|
438
|
40
|
|
|
41
|
$this->resetShippingAddress();
|
|
42
|
$this->resetBillingAddress();
|
hpdl
|
418
|
43
|
}
|
|
44
|
|
hpdl
|
420
|
45
|
$this->_contents =& $_SESSION['osC_ShoppingCart_data']['contents'];
|
hpdl
|
435
|
46
|
$this->_sub_total =& $_SESSION['osC_ShoppingCart_data']['sub_total_cost'];
|
hpdl
|
420
|
47
|
$this->_total =& $_SESSION['osC_ShoppingCart_data']['total_cost'];
|
|
48
|
$this->_weight =& $_SESSION['osC_ShoppingCart_data']['total_weight'];
|
hpdl
|
435
|
49
|
$this->_tax =& $_SESSION['osC_ShoppingCart_data']['tax'];
|
|
50
|
$this->_tax_groups =& $_SESSION['osC_ShoppingCart_data']['tax_groups'];
|
hpdl
|
439
|
51
|
$this->_shipping_boxes_weight =& $_SESSION['osC_ShoppingCart_data']['shipping_boxes_weight'];
|
|
52
|
$this->_shipping_boxes =& $_SESSION['osC_ShoppingCart_data']['shipping_boxes'];
|
hpdl
|
435
|
53
|
$this->_cartID =& $_SESSION['osC_ShoppingCart_data']['cart_id'];
|
hpdl
|
421
|
54
|
$this->_shipping_address =& $_SESSION['osC_ShoppingCart_data']['shipping_address'];
|
|
55
|
$this->_shipping_method =& $_SESSION['osC_ShoppingCart_data']['shipping_method'];
|
|
56
|
$this->_billing_address =& $_SESSION['osC_ShoppingCart_data']['billing_address'];
|
|
57
|
$this->_billing_method =& $_SESSION['osC_ShoppingCart_data']['billing_method'];
|
hpdl
|
439
|
58
|
$this->_order_totals =& $_SESSION['osC_ShoppingCart_data']['order_totals'];
|
hpdl
|
1
|
59
|
}
|
|
60
|
|
hpdl
|
418
|
61
|
function hasContents() {
|
hpdl
|
420
|
62
|
return !empty($this->_contents);
|
hpdl
|
418
|
63
|
}
|
|
64
|
|
|
65
|
function synchronizeWithDatabase() {
|
hpdl
|
809
|
66
|
global $osC_Database, $osC_Services, $osC_Language, $osC_Customer, $osC_Image;
|
hpdl
|
1
|
67
|
|
hpdl
|
809
|
68
|
if (!$osC_Customer->isLoggedOn()) {
|
hpdl
|
418
|
69
|
return false;
|
|
70
|
}
|
hpdl
|
1
|
71
|
|
|
72
|
// insert current cart contents in database
|
hpdl
|
418
|
73
|
if ($this->hasContents()) {
|
hpdl
|
809
|
74
|
foreach ($this->_contents as $products_id_string => $data) {
|
hpdl
|
420
|
75
|
$Qproduct = $osC_Database->query('select products_id, customers_basket_quantity from :table_customers_basket where customers_id = :customers_id and products_id = :products_id');
|
hpdl
|
19
|
76
|
$Qproduct->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
|
hpdl
|
184
|
77
|
$Qproduct->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
809
|
78
|
$Qproduct->bindValue(':products_id', $products_id_string);
|
hpdl
|
19
|
79
|
$Qproduct->execute();
|
|
80
|
|
hpdl
|
418
|
81
|
if ($Qproduct->numberOfRows() > 0) {
|
|
82
|
$Qupdate = $osC_Database->query('update :table_customers_basket set customers_basket_quantity = :customers_basket_quantity where customers_id = :customers_id and products_id = :products_id');
|
|
83
|
$Qupdate->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
|
hpdl
|
420
|
84
|
$Qupdate->bindInt(':customers_basket_quantity', $data['quantity'] + $Qproduct->valueInt('customers_basket_quantity'));
|
hpdl
|
418
|
85
|
$Qupdate->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
809
|
86
|
$Qupdate->bindValue(':products_id', $products_id_string);
|
hpdl
|
418
|
87
|
$Qupdate->execute();
|
|
88
|
} else {
|
hpdl
|
387
|
89
|
$Qnew = $osC_Database->query('insert into :table_customers_basket (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values (:customers_id, :products_id, :customers_basket_quantity, now())');
|
hpdl
|
19
|
90
|
$Qnew->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
|
hpdl
|
184
|
91
|
$Qnew->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
809
|
92
|
$Qnew->bindValue(':products_id', $products_id_string);
|
hpdl
|
420
|
93
|
$Qnew->bindInt(':customers_basket_quantity', $data['quantity']);
|
hpdl
|
19
|
94
|
$Qnew->execute();
|
hpdl
|
1
|
95
|
}
|
|
96
|
}
|
|
97
|
}
|
|
98
|
|
|
99
|
// reset per-session cart contents, but not the database contents
|
hpdl
|
418
|
100
|
$this->reset();
|
hpdl
|
1
|
101
|
|
hpdl
|
599
|
102
|
$Qproducts = $osC_Database->query('select cb.products_id, cb.customers_basket_quantity, cb.customers_basket_date_added, p.products_price, p.products_tax_class_id, p.products_weight, p.products_weight_class, pd.products_name, pd.products_keyword, i.image from :table_customers_basket cb, :table_products p left join :table_products_images i on (p.products_id = i.products_id and i.default_flag = :default_flag), :table_products_description pd where cb.customers_id = :customers_id and cb.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = :language_id order by cb.customers_basket_date_added desc');
|
hpdl
|
19
|
103
|
$Qproducts->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
|
hpdl
|
418
|
104
|
$Qproducts->bindTable(':table_products', TABLE_PRODUCTS);
|
hpdl
|
556
|
105
|
$Qproducts->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
|
hpdl
|
420
|
106
|
$Qproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
|
hpdl
|
583
|
107
|
$Qproducts->bindInt(':default_flag', 1);
|
hpdl
|
184
|
108
|
$Qproducts->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
420
|
109
|
$Qproducts->bindInt(':language_id', $osC_Language->getID());
|
hpdl
|
19
|
110
|
$Qproducts->execute();
|
|
111
|
|
|
112
|
while ($Qproducts->next()) {
|
hpdl
|
809
|
113
|
$product = explode('#', $Qproducts->value('products_id'), 2);
|
|
114
|
$attributes_array = array();
|
|
115
|
|
|
116
|
if (isset($product[1])) {
|
|
117
|
$attributes = explode(';', $product[1]);
|
|
118
|
|
|
119
|
foreach ($attributes as $set) {
|
|
120
|
$attribute = explode(':', $set);
|
|
121
|
|
|
122
|
if (!is_numeric($attribute[0]) || !is_numeric($attribute[1])) {
|
|
123
|
continue 2; // skip product
|
|
124
|
}
|
|
125
|
|
|
126
|
$attributes_array[$attribute[0]] = $attribute[1];
|
|
127
|
}
|
|
128
|
}
|
|
129
|
|
hpdl
|
420
|
130
|
$price = $Qproducts->value('products_price');
|
hpdl
|
418
|
131
|
|
hpdl
|
809
|
132
|
if ($osC_Services->isStarted('specials')) {
|
|
133
|
global $osC_Specials;
|
hpdl
|
418
|
134
|
|
hpdl
|
809
|
135
|
if ($new_price = $osC_Specials->getPrice(osc_get_product_id($Qproducts->value('products_id')))) {
|
|
136
|
$price = $new_price;
|
|
137
|
}
|
hpdl
|
418
|
138
|
}
|
|
139
|
|
hpdl
|
420
|
140
|
$this->_contents[$Qproducts->value('products_id')] = array('id' => $Qproducts->value('products_id'),
|
|
141
|
'name' => $Qproducts->value('products_name'),
|
|
142
|
'keyword' => $Qproducts->value('products_keyword'),
|
hpdl
|
555
|
143
|
'image' => $Qproducts->value('image'),
|
hpdl
|
420
|
144
|
'price' => $price,
|
|
145
|
'final_price' => $price,
|
|
146
|
'quantity' => $Qproducts->valueInt('customers_basket_quantity'),
|
|
147
|
'weight' => $Qproducts->value('products_weight'),
|
|
148
|
'tax_class_id' => $Qproducts->valueInt('products_tax_class_id'),
|
|
149
|
'date_added' => osC_DateTime::getShort($Qproducts->value('customers_basket_date_added')),
|
|
150
|
'weight_class_id' => $Qproducts->valueInt('products_weight_class'));
|
|
151
|
|
hpdl
|
809
|
152
|
if (!empty($attributes_array)) {
|
|
153
|
foreach ($attributes_array as $option_id => $value_id) {
|
|
154
|
$Qattributes = $osC_Database->query('select pa.options_values_price, pa.price_prefix, po.products_options_name, pov.products_options_values_name from :table_products_attributes pa, :table_products_options po, :table_products_options_values pov where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_values_id = :options_values_id and pa.options_id = po.products_options_id and po.language_id = :language_id and pa.options_values_id = pov.products_options_values_id and pov.language_id = :language_id');
|
|
155
|
$Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
|
|
156
|
$Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
|
|
157
|
$Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
|
|
158
|
$Qattributes->bindInt(':products_id', osc_get_product_id($Qproducts->value('products_id')));
|
|
159
|
$Qattributes->bindInt(':options_id', $option_id);
|
|
160
|
$Qattributes->bindInt(':options_values_id', $value_id);
|
|
161
|
$Qattributes->bindInt(':language_id', $osC_Language->getID());
|
|
162
|
$Qattributes->bindInt(':language_id', $osC_Language->getID());
|
|
163
|
$Qattributes->execute();
|
hpdl
|
19
|
164
|
|
hpdl
|
810
|
165
|
if ($Qattributes->numberOfRows() > 0) {
|
hpdl
|
809
|
166
|
$this->_contents[$Qproducts->value('products_id')]['attributes'][$option_id] = array('options_id' => $option_id,
|
|
167
|
'options_values_id' => $value_id,
|
|
168
|
'products_options_name' => $Qattributes->value('products_options_name'),
|
|
169
|
'products_options_values_name' => $Qattributes->value('products_options_values_name'),
|
|
170
|
'options_values_price' => $Qattributes->value('options_values_price'),
|
|
171
|
'price_prefix' => $Qattributes->value('price_prefix'));
|
hpdl
|
420
|
172
|
|
hpdl
|
809
|
173
|
if ($Qattributes->value('price_prefix') == '+') {
|
|
174
|
$this->_contents[$Qproducts->value('products_id')]['final_price'] += $Qattributes->value('options_values_price');
|
|
175
|
} else {
|
|
176
|
$this->_contents[$Qproducts->value('products_id')]['final_price'] -= $Qattributes->value('options_values_price');
|
|
177
|
}
|
hpdl
|
810
|
178
|
} else {
|
|
179
|
unset($this->_contents[$Qproducts->value('products_id')]);
|
|
180
|
continue 2; // skip product
|
hpdl
|
809
|
181
|
}
|
hpdl
|
420
|
182
|
}
|
hpdl
|
1
|
183
|
}
|
|
184
|
}
|
|
185
|
|
hpdl
|
418
|
186
|
$this->_cleanUp();
|
hpdl
|
419
|
187
|
$this->_calculate();
|
hpdl
|
1
|
188
|
}
|
|
189
|
|
|
190
|
function reset($reset_database = false) {
|
hpdl
|
199
|
191
|
global $osC_Database, $osC_Customer;
|
hpdl
|
1
|
192
|
|
hpdl
|
418
|
193
|
if (($reset_database === true) && $osC_Customer->isLoggedOn()) {
|
hpdl
|
19
|
194
|
$Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id');
|
|
195
|
$Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
|
hpdl
|
184
|
196
|
$Qdelete->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
19
|
197
|
$Qdelete->execute();
|
hpdl
|
418
|
198
|
}
|
hpdl
|
19
|
199
|
|
hpdl
|
420
|
200
|
$this->_contents = array();
|
hpdl
|
435
|
201
|
$this->_sub_total = 0;
|
hpdl
|
420
|
202
|
$this->_total = 0;
|
|
203
|
$this->_weight = 0;
|
hpdl
|
435
|
204
|
$this->_tax = 0;
|
|
205
|
$this->_tax_groups = array();
|
hpdl
|
439
|
206
|
$this->_cartID = $this->generateCartID();
|
hpdl
|
420
|
207
|
$this->_content_type = null;
|
hpdl
|
439
|
208
|
|
hpdl
|
438
|
209
|
$this->resetShippingAddress();
|
hpdl
|
439
|
210
|
$this->resetShippingMethod();
|
hpdl
|
438
|
211
|
$this->resetBillingAddress();
|
hpdl
|
439
|
212
|
$this->resetBillingMethod();
|
hpdl
|
1
|
213
|
}
|
|
214
|
|
hpdl
|
809
|
215
|
function add($products_id_string, $attributes = null, $quantity = null) {
|
|
216
|
global $osC_Database, $osC_Services, $osC_Language, $osC_Customer, $osC_Image;
|
hpdl
|
1
|
217
|
|
hpdl
|
809
|
218
|
$products_id_string = osc_get_product_id_string($products_id_string, $attributes);
|
hpdl
|
734
|
219
|
$products_id = osc_get_product_id($products_id_string);
|
hpdl
|
1
|
220
|
|
hpdl
|
418
|
221
|
if (is_numeric($products_id)) {
|
hpdl
|
599
|
222
|
$Qcheck = $osC_Database->query('select p.products_price, p.products_tax_class_id, p.products_weight, p.products_weight_class, p.products_status, i.image from :table_products p left join :table_products_images i on (p.products_id = i.products_id and i.default_flag = :default_flag) where p.products_id = :products_id');
|
hpdl
|
19
|
223
|
$Qcheck->bindTable(':table_products', TABLE_PRODUCTS);
|
hpdl
|
556
|
224
|
$Qcheck->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
|
hpdl
|
583
|
225
|
$Qcheck->bindInt(':default_flag', 1);
|
hpdl
|
19
|
226
|
$Qcheck->bindInt(':products_id', $products_id);
|
|
227
|
$Qcheck->execute();
|
hpdl
|
1
|
228
|
|
hpdl
|
418
|
229
|
if ($Qcheck->valueInt('products_status') === 1) {
|
|
230
|
if ($this->exists($products_id_string)) {
|
hpdl
|
809
|
231
|
if (!is_numeric($quantity)) {
|
hpdl
|
418
|
232
|
$quantity = $this->getQuantity($products_id_string) + 1;
|
|
233
|
}
|
|
234
|
|
hpdl
|
420
|
235
|
$this->_contents[$products_id_string]['quantity'] = $quantity;
|
hpdl
|
418
|
236
|
|
|
237
|
// update database
|
|
238
|
if ($osC_Customer->isLoggedOn()) {
|
|
239
|
$Qupdate = $osC_Database->query('update :table_customers_basket set customers_basket_quantity = :customers_basket_quantity where customers_id = :customers_id and products_id = :products_id');
|
|
240
|
$Qupdate->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
|
|
241
|
$Qupdate->bindInt(':customers_basket_quantity', $quantity);
|
|
242
|
$Qupdate->bindInt(':customers_id', $osC_Customer->getID());
|
|
243
|
$Qupdate->bindValue(':products_id', $products_id_string);
|
|
244
|
$Qupdate->execute();
|
|
245
|
}
|
hpdl
|
1
|
246
|
} else {
|
hpdl
|
809
|
247
|
if (!is_numeric($quantity)) {
|
hpdl
|
418
|
248
|
$quantity = 1;
|
|
249
|
}
|
|
250
|
|
hpdl
|
420
|
251
|
$Qproduct = $osC_Database->query('select products_name, products_keyword from :table_products_description where products_id = :products_id and language_id = :language_id');
|
|
252
|
$Qproduct->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
|
|
253
|
$Qproduct->bindInt(':products_id', $products_id);
|
|
254
|
$Qproduct->bindInt(':language_id', $osC_Language->getID());
|
|
255
|
$Qproduct->execute();
|
hpdl
|
418
|
256
|
|
hpdl
|
420
|
257
|
$price = $Qcheck->value('products_price');
|
|
258
|
|
hpdl
|
809
|
259
|
if ($osC_Services->isStarted('specials')) {
|
|
260
|
global $osC_Specials;
|
hpdl
|
418
|
261
|
|
hpdl
|
809
|
262
|
if ($new_price = $osC_Specials->getPrice($products_id)) {
|
|
263
|
$price = $new_price;
|
|
264
|
}
|
hpdl
|
418
|
265
|
}
|
|
266
|
|
hpdl
|
420
|
267
|
$this->_contents[$products_id_string] = array('id' => $products_id_string,
|
|
268
|
'name' => $Qproduct->value('products_name'),
|
|
269
|
'keyword' => $Qproduct->value('products_keyword'),
|
hpdl
|
555
|
270
|
'image' => $Qcheck->value('image'),
|
hpdl
|
420
|
271
|
'price' => $price,
|
|
272
|
'final_price' => $price,
|
|
273
|
'quantity' => $quantity,
|
|
274
|
'weight' => $Qcheck->value('products_weight'),
|
|
275
|
'tax_class_id' => $Qcheck->valueInt('products_tax_class_id'),
|
|
276
|
'date_added' => osC_DateTime::getShort(osC_DateTime::getNow()),
|
|
277
|
'weight_class_id' => $Qcheck->valueInt('products_weight_class'));
|
|
278
|
|
hpdl
|
1
|
279
|
// insert into database
|
hpdl
|
19
|
280
|
if ($osC_Customer->isLoggedOn()) {
|
hpdl
|
387
|
281
|
$Qnew = $osC_Database->query('insert into :table_customers_basket (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values (:customers_id, :products_id, :customers_basket_quantity, now())');
|
hpdl
|
19
|
282
|
$Qnew->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
|
hpdl
|
184
|
283
|
$Qnew->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
19
|
284
|
$Qnew->bindValue(':products_id', $products_id_string);
|
hpdl
|
418
|
285
|
$Qnew->bindInt(':customers_basket_quantity', $quantity);
|
hpdl
|
19
|
286
|
$Qnew->execute();
|
|
287
|
}
|
hpdl
|
1
|
288
|
|
hpdl
|
809
|
289
|
if (is_array($attributes) && !empty($attributes)) {
|
hpdl
|
418
|
290
|
foreach ($attributes as $option => $value) {
|
hpdl
|
420
|
291
|
$Qattributes = $osC_Database->query('select pa.options_values_price, pa.price_prefix, po.products_options_name, pov.products_options_values_name from :table_products_attributes pa, :table_products_options po, :table_products_options_values pov where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_values_id = :options_values_id and pa.options_id = po.products_options_id and po.language_id = :language_id and pa.options_values_id = pov.products_options_values_id and pov.language_id = :language_id');
|
hpdl
|
418
|
292
|
$Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
|
hpdl
|
420
|
293
|
$Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
|
|
294
|
$Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
|
hpdl
|
418
|
295
|
$Qattributes->bindValue(':products_id', $products_id);
|
|
296
|
$Qattributes->bindInt(':options_id', $option);
|
|
297
|
$Qattributes->bindInt(':options_values_id', $value);
|
hpdl
|
420
|
298
|
$Qattributes->bindInt(':language_id', $osC_Language->getID());
|
|
299
|
$Qattributes->bindInt(':language_id', $osC_Language->getID());
|
hpdl
|
418
|
300
|
$Qattributes->execute();
|
|
301
|
|
hpdl
|
420
|
302
|
$this->_contents[$products_id_string]['attributes'][$option] = array('options_id' => $option,
|
|
303
|
'options_values_id' => $value,
|
|
304
|
'products_options_name' => $Qattributes->value('products_options_name'),
|
|
305
|
'products_options_values_name' => $Qattributes->value('products_options_values_name'),
|
|
306
|
'options_values_price' => $Qattributes->value('options_values_price'),
|
|
307
|
'price_prefix' => $Qattributes->value('price_prefix'));
|
hpdl
|
418
|
308
|
|
hpdl
|
420
|
309
|
if ($Qattributes->value('price_prefix') == '+') {
|
|
310
|
$this->_contents[$products_id_string]['final_price'] += $Qattributes->value('options_values_price');
|
|
311
|
} else {
|
|
312
|
$this->_contents[$products_id_string]['final_price'] -= $Qattributes->value('options_values_price');
|
|
313
|
}
|
hpdl
|
1
|
314
|
}
|
|
315
|
}
|
|
316
|
}
|
|
317
|
|
hpdl
|
418
|
318
|
$this->_cleanUp();
|
hpdl
|
419
|
319
|
$this->_calculate();
|
hpdl
|
1
|
320
|
}
|
|
321
|
}
|
|
322
|
}
|
|
323
|
|
hpdl
|
418
|
324
|
function numberOfItems() {
|
|
325
|
$total = 0;
|
hpdl
|
1
|
326
|
|
hpdl
|
418
|
327
|
if ($this->hasContents()) {
|
hpdl
|
420
|
328
|
foreach (array_keys($this->_contents) as $products_id) {
|
hpdl
|
418
|
329
|
$total += $this->getQuantity($products_id);
|
hpdl
|
19
|
330
|
}
|
hpdl
|
1
|
331
|
}
|
|
332
|
|
hpdl
|
418
|
333
|
return $total;
|
hpdl
|
1
|
334
|
}
|
|
335
|
|
hpdl
|
418
|
336
|
function getQuantity($products_id) {
|
hpdl
|
420
|
337
|
if (isset($this->_contents[$products_id])) {
|
|
338
|
return $this->_contents[$products_id]['quantity'];
|
hpdl
|
1
|
339
|
}
|
hpdl
|
418
|
340
|
|
|
341
|
return 0;
|
hpdl
|
1
|
342
|
}
|
|
343
|
|
hpdl
|
418
|
344
|
function exists($products_id) {
|
hpdl
|
420
|
345
|
return isset($this->_contents[$products_id]);
|
hpdl
|
1
|
346
|
}
|
|
347
|
|
|
348
|
function remove($products_id) {
|
hpdl
|
19
|
349
|
global $osC_Database, $osC_Customer;
|
hpdl
|
1
|
350
|
|
hpdl
|
420
|
351
|
unset($this->_contents[$products_id]);
|
hpdl
|
418
|
352
|
|
hpdl
|
1
|
353
|
// remove from database
|
|
354
|
if ($osC_Customer->isLoggedOn()) {
|
hpdl
|
19
|
355
|
$Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id and products_id = :products_id');
|
|
356
|
$Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
|
hpdl
|
184
|
357
|
$Qdelete->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
19
|
358
|
$Qdelete->bindValue(':products_id', $products_id);
|
|
359
|
$Qdelete->execute();
|
hpdl
|
1
|
360
|
}
|
|
361
|
|
hpdl
|
419
|
362
|
$this->_calculate();
|
hpdl
|
1
|
363
|
}
|
|
364
|
|
hpdl
|
420
|
365
|
function getProducts() {
|
|
366
|
static $_is_sorted = false;
|
hpdl
|
19
|
367
|
|
hpdl
|
420
|
368
|
if ($_is_sorted === false) {
|
|
369
|
$_is_sorted = true;
|
hpdl
|
1
|
370
|
|
hpdl
|
420
|
371
|
uasort($this->_contents, array('osC_ShoppingCart', '_uasortProductsByDateAdded'));
|
hpdl
|
1
|
372
|
}
|
|
373
|
|
hpdl
|
420
|
374
|
return $this->_contents;
|
hpdl
|
1
|
375
|
}
|
|
376
|
|
hpdl
|
435
|
377
|
function getSubTotal() {
|
|
378
|
return $this->_sub_total;
|
|
379
|
}
|
|
380
|
|
hpdl
|
420
|
381
|
function getTotal() {
|
|
382
|
return $this->_total;
|
|
383
|
}
|
hpdl
|
1
|
384
|
|
hpdl
|
420
|
385
|
function getWeight() {
|
|
386
|
return $this->_weight;
|
hpdl
|
1
|
387
|
}
|
|
388
|
|
hpdl
|
420
|
389
|
function generateCartID($length = 5) {
|
hpdl
|
734
|
390
|
return osc_create_random_string($length, 'digits');
|
hpdl
|
1
|
391
|
}
|
|
392
|
|
hpdl
|
420
|
393
|
function hasCartID() {
|
|
394
|
return isset($this->_cartID);
|
hpdl
|
1
|
395
|
}
|
|
396
|
|
hpdl
|
420
|
397
|
function getCartID() {
|
|
398
|
return $this->_cartID;
|
hpdl
|
1
|
399
|
}
|
|
400
|
|
hpdl
|
418
|
401
|
function getContentType() {
|
hpdl
|
19
|
402
|
global $osC_Database;
|
|
403
|
|
hpdl
|
420
|
404
|
$this->_content_type = 'physical';
|
hpdl
|
1
|
405
|
|
hpdl
|
500
|
406
|
if ( (DOWNLOAD_ENABLED == '1') && $this->hasContents() ) {
|
hpdl
|
420
|
407
|
foreach ($this->_contents as $products_id => $data) {
|
hpdl
|
418
|
408
|
if (isset($data['attributes'])) {
|
|
409
|
foreach ($data['attributes'] as $value) {
|
hpdl
|
19
|
410
|
$Qcheck = $osC_Database->query('select count(*) as total from :table_products_attributes pa, :table_products_attributes_download pad where pa.products_id = :products_id and pa.options_values_id = :options_values_id and pa.products_attributes_id = pad.products_attributes_id');
|
|
411
|
$Qcheck->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
|
|
412
|
$Qcheck->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD);
|
|
413
|
$Qcheck->bindInt(':products_id', $products_id);
|
hpdl
|
420
|
414
|
$Qcheck->bindInt(':options_values_id', $value['options_values_id']);
|
hpdl
|
19
|
415
|
$Qcheck->execute();
|
hpdl
|
1
|
416
|
|
hpdl
|
19
|
417
|
if ($Qcheck->valueInt('total') > 0) {
|
hpdl
|
420
|
418
|
switch ($this->_content_type) {
|
hpdl
|
1
|
419
|
case 'physical':
|
hpdl
|
420
|
420
|
$this->_content_type = 'mixed';
|
hpdl
|
1
|
421
|
|
hpdl
|
420
|
422
|
return $this->_content_type;
|
hpdl
|
1
|
423
|
break;
|
|
424
|
default:
|
hpdl
|
420
|
425
|
$this->_content_type = 'virtual';
|
hpdl
|
1
|
426
|
break;
|
|
427
|
}
|
|
428
|
} else {
|
hpdl
|
420
|
429
|
switch ($this->_content_type) {
|
hpdl
|
1
|
430
|
case 'virtual':
|
hpdl
|
420
|
431
|
$this->_content_type = 'mixed';
|
hpdl
|
1
|
432
|
|
hpdl
|
420
|
433
|
return $this->_content_type;
|
hpdl
|
1
|
434
|
break;
|
|
435
|
default:
|
hpdl
|
420
|
436
|
$this->_content_type = 'physical';
|
hpdl
|
1
|
437
|
break;
|
|
438
|
}
|
|
439
|
}
|
|
440
|
}
|
|
441
|
} else {
|
hpdl
|
420
|
442
|
switch ($this->_content_type) {
|
hpdl
|
1
|
443
|
case 'virtual':
|
hpdl
|
420
|
444
|
$this->_content_type = 'mixed';
|
hpdl
|
1
|
445
|
|
hpdl
|
420
|
446
|
return $this->_content_type;
|
hpdl
|
1
|
447
|
break;
|
|
448
|
default:
|
hpdl
|
420
|
449
|
$this->_content_type = 'physical';
|
hpdl
|
1
|
450
|
break;
|
|
451
|
}
|
|
452
|
}
|
|
453
|
}
|
|
454
|
}
|
|
455
|
|
hpdl
|
420
|
456
|
return $this->_content_type;
|
hpdl
|
1
|
457
|
}
|
hpdl
|
418
|
458
|
|
hpdl
|
420
|
459
|
function hasAttributes($products_id) {
|
hpdl
|
809
|
460
|
return isset($this->_contents[$products_id]['attributes']) && !empty($this->_contents[$products_id]['attributes']);
|
hpdl
|
420
|
461
|
}
|
|
462
|
|
|
463
|
function getAttributes($products_id) {
|
hpdl
|
809
|
464
|
if (isset($this->_contents[$products_id]['attributes']) && !empty($this->_contents[$products_id]['attributes'])) {
|
hpdl
|
420
|
465
|
return $this->_contents[$products_id]['attributes'];
|
|
466
|
}
|
|
467
|
}
|
|
468
|
|
|
469
|
function isInStock($products_id) {
|
|
470
|
global $osC_Database;
|
|
471
|
|
|
472
|
$Qstock = $osC_Database->query('select products_quantity from :table_products where products_id = :products_id');
|
|
473
|
$Qstock->bindTable(':table_products', TABLE_PRODUCTS);
|
hpdl
|
734
|
474
|
$Qstock->bindInt(':products_id', osc_get_product_id($products_id));
|
hpdl
|
420
|
475
|
$Qstock->execute();
|
|
476
|
|
|
477
|
if (($Qstock->valueInt('products_quantity') - $this->_contents[$products_id]['quantity']) > 0) {
|
|
478
|
return true;
|
|
479
|
} elseif ($this->_products_in_stock === true) {
|
|
480
|
$this->_products_in_stock = false;
|
|
481
|
}
|
|
482
|
|
|
483
|
return false;
|
|
484
|
}
|
|
485
|
|
|
486
|
function hasStock() {
|
|
487
|
return $this->_products_in_stock;
|
|
488
|
}
|
|
489
|
|
hpdl
|
421
|
490
|
function hasShippingAddress() {
|
|
491
|
return isset($this->_shipping_address) && isset($this->_shipping_address['id']);
|
|
492
|
}
|
|
493
|
|
|
494
|
function setShippingAddress($address_id) {
|
|
495
|
global $osC_Database, $osC_Customer;
|
|
496
|
|
hpdl
|
439
|
497
|
$previous_address = false;
|
|
498
|
|
|
499
|
if (isset($this->_shipping_address['id'])) {
|
|
500
|
$previous_address = $this->getShippingAddress();
|
|
501
|
}
|
|
502
|
|
hpdl
|
732
|
503
|
$Qaddress = $osC_Database->query('select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, ab.entry_telephone, z.zone_code, z.zone_name, ab.entry_country_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format, ab.entry_state from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) left join :table_countries c on (ab.entry_country_id = c.countries_id) where ab.customers_id = :customers_id and ab.address_book_id = :address_book_id');
|
hpdl
|
425
|
504
|
$Qaddress->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
|
|
505
|
$Qaddress->bindTable(':table_zones', TABLE_ZONES);
|
|
506
|
$Qaddress->bindTable(':table_countries', TABLE_COUNTRIES);
|
|
507
|
$Qaddress->bindInt(':customers_id', $osC_Customer->getID());
|
|
508
|
$Qaddress->bindInt(':address_book_id', $address_id);
|
|
509
|
$Qaddress->execute();
|
hpdl
|
421
|
510
|
|
|
511
|
$this->_shipping_address = array('id' => $address_id,
|
hpdl
|
425
|
512
|
'firstname' => $Qaddress->valueProtected('entry_firstname'),
|
|
513
|
'lastname' => $Qaddress->valueProtected('entry_lastname'),
|
|
514
|
'company' => $Qaddress->valueProtected('entry_company'),
|
|
515
|
'street_address' => $Qaddress->valueProtected('entry_street_address'),
|
|
516
|
'suburb' => $Qaddress->valueProtected('entry_suburb'),
|
|
517
|
'city' => $Qaddress->valueProtected('entry_city'),
|
|
518
|
'postcode' => $Qaddress->valueProtected('entry_postcode'),
|
hpdl
|
809
|
519
|
'state' => (!osc_empty($Qaddress->valueProtected('entry_state'))) ? $Qaddress->valueProtected('entry_state') : $Qaddress->valueProtected('zone_name'),
|
hpdl
|
425
|
520
|
'zone_id' => $Qaddress->valueInt('entry_zone_id'),
|
hpdl
|
479
|
521
|
'zone_code' => $Qaddress->value('zone_code'),
|
hpdl
|
425
|
522
|
'country_id' => $Qaddress->valueInt('entry_country_id'),
|
|
523
|
'country_title' => $Qaddress->value('countries_name'),
|
|
524
|
'country_iso_code_2' => $Qaddress->value('countries_iso_code_2'),
|
|
525
|
'country_iso_code_3' => $Qaddress->value('countries_iso_code_3'),
|
hpdl
|
732
|
526
|
'format' => $Qaddress->value('address_format'),
|
hpdl
|
479
|
527
|
'telephone_number' => $Qaddress->value('entry_telephone'));
|
hpdl
|
439
|
528
|
|
|
529
|
if ( is_array($previous_address) && ( ($previous_address['id'] != $this->_shipping_address['id']) || ($previous_address['country_id'] != $this->_shipping_address['country_id']) || ($previous_address['zone_id'] != $this->_shipping_address['zone_id']) || ($previous_address['state'] != $this->_shipping_address['state']) || ($previous_address['postcode'] != $this->_shipping_address['postcode']) ) ) {
|
|
530
|
$this->_calculate();
|
|
531
|
}
|
hpdl
|
421
|
532
|
}
|
|
533
|
|
|
534
|
function getShippingAddress($key = '') {
|
|
535
|
if (empty($key)) {
|
|
536
|
return $this->_shipping_address;
|
|
537
|
}
|
|
538
|
|
|
539
|
return $this->_shipping_address[$key];
|
|
540
|
}
|
|
541
|
|
hpdl
|
422
|
542
|
function resetShippingAddress() {
|
hpdl
|
438
|
543
|
global $osC_Customer;
|
|
544
|
|
hpdl
|
439
|
545
|
$this->_shipping_address = array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY);
|
hpdl
|
438
|
546
|
|
|
547
|
if ($osC_Customer->isLoggedOn() && $osC_Customer->hasDefaultAddress()) {
|
|
548
|
$this->setShippingAddress($osC_Customer->getDefaultAddressID());
|
|
549
|
}
|
hpdl
|
422
|
550
|
}
|
|
551
|
|
hpdl
|
439
|
552
|
function setShippingMethod($shipping_array, $calculate_total = true) {
|
hpdl
|
421
|
553
|
$this->_shipping_method = $shipping_array;
|
hpdl
|
439
|
554
|
|
|
555
|
if ($calculate_total === true) {
|
|
556
|
$this->_calculate(false);
|
|
557
|
}
|
hpdl
|
421
|
558
|
}
|
|
559
|
|
|
560
|
function getShippingMethod($key = '') {
|
|
561
|
if (empty($key)) {
|
|
562
|
return $this->_shipping_method;
|
|
563
|
}
|
|
564
|
|
|
565
|
return $this->_shipping_method[$key];
|
|
566
|
}
|
|
567
|
|
|
568
|
function resetShippingMethod() {
|
|
569
|
$this->_shipping_method = array();
|
hpdl
|
438
|
570
|
|
hpdl
|
439
|
571
|
$this->_calculate();
|
hpdl
|
421
|
572
|
}
|
|
573
|
|
|
574
|
function hasShippingMethod() {
|
|
575
|
return !empty($this->_shipping_method);
|
|
576
|
}
|
|
577
|
|
|
578
|
function hasBillingAddress() {
|
hpdl
|
439
|
579
|
return isset($this->_billing_address) && isset($this->_billing_address['id']);
|
hpdl
|
421
|
580
|
}
|
|
581
|
|
|
582
|
function setBillingAddress($address_id) {
|
|
583
|
global $osC_Database, $osC_Customer;
|
|
584
|
|
hpdl
|
439
|
585
|
$previous_address = false;
|
|
586
|
|
|
587
|
if (isset($this->_billing_address['id'])) {
|
|
588
|
$previous_address = $this->getBillingAddress();
|
|
589
|
}
|
|
590
|
|
hpdl
|
732
|
591
|
$Qaddress = $osC_Database->query('select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, ab.entry_telephone, z.zone_code, z.zone_name, ab.entry_country_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format, ab.entry_state from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) left join :table_countries c on (ab.entry_country_id = c.countries_id) where ab.customers_id = :customers_id and ab.address_book_id = :address_book_id');
|
hpdl
|
421
|
592
|
$Qaddress->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
|
|
593
|
$Qaddress->bindTable(':table_zones', TABLE_ZONES);
|
|
594
|
$Qaddress->bindTable(':table_countries', TABLE_COUNTRIES);
|
|
595
|
$Qaddress->bindInt(':customers_id', $osC_Customer->getID());
|
|
596
|
$Qaddress->bindInt(':address_book_id', $address_id);
|
|
597
|
$Qaddress->execute();
|
|
598
|
|
|
599
|
$this->_billing_address = array('id' => $address_id,
|
|
600
|
'firstname' => $Qaddress->valueProtected('entry_firstname'),
|
|
601
|
'lastname' => $Qaddress->valueProtected('entry_lastname'),
|
|
602
|
'company' => $Qaddress->valueProtected('entry_company'),
|
|
603
|
'street_address' => $Qaddress->valueProtected('entry_street_address'),
|
|
604
|
'suburb' => $Qaddress->valueProtected('entry_suburb'),
|
|
605
|
'city' => $Qaddress->valueProtected('entry_city'),
|
|
606
|
'postcode' => $Qaddress->valueProtected('entry_postcode'),
|
hpdl
|
809
|
607
|
'state' => (!osc_empty($Qaddress->valueProtected('entry_state'))) ? $Qaddress->valueProtected('entry_state') : $Qaddress->valueProtected('zone_name'),
|
hpdl
|
421
|
608
|
'zone_id' => $Qaddress->valueInt('entry_zone_id'),
|
hpdl
|
479
|
609
|
'zone_code' => $Qaddress->value('zone_code'),
|
hpdl
|
421
|
610
|
'country_id' => $Qaddress->valueInt('entry_country_id'),
|
hpdl
|
425
|
611
|
'country_title' => $Qaddress->value('countries_name'),
|
|
612
|
'country_iso_code_2' => $Qaddress->value('countries_iso_code_2'),
|
|
613
|
'country_iso_code_3' => $Qaddress->value('countries_iso_code_3'),
|
hpdl
|
732
|
614
|
'format' => $Qaddress->value('address_format'),
|
hpdl
|
479
|
615
|
'telephone_number' => $Qaddress->value('entry_telephone'));
|
hpdl
|
439
|
616
|
|
|
617
|
if ( is_array($previous_address) && ( ($previous_address['id'] != $this->_billing_address['id']) || ($previous_address['country_id'] != $this->_billing_address['country_id']) || ($previous_address['zone_id'] != $this->_billing_address['zone_id']) || ($previous_address['state'] != $this->_billing_address['state']) || ($previous_address['postcode'] != $this->_billing_address['postcode']) ) ) {
|
|
618
|
$this->_calculate();
|
|
619
|
}
|
hpdl
|
421
|
620
|
}
|
|
621
|
|
|
622
|
function getBillingAddress($key = '') {
|
|
623
|
if (empty($key)) {
|
|
624
|
return $this->_billing_address;
|
|
625
|
}
|
|
626
|
|
|
627
|
return $this->_billing_address[$key];
|
|
628
|
}
|
|
629
|
|
hpdl
|
424
|
630
|
function resetBillingAddress() {
|
hpdl
|
438
|
631
|
global $osC_Customer;
|
|
632
|
|
hpdl
|
439
|
633
|
$this->_billing_address = array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY);
|
hpdl
|
438
|
634
|
|
|
635
|
if ($osC_Customer->isLoggedOn() && $osC_Customer->hasDefaultAddress()) {
|
|
636
|
$this->setBillingAddress($osC_Customer->getDefaultAddressID());
|
|
637
|
}
|
hpdl
|
424
|
638
|
}
|
|
639
|
|
hpdl
|
421
|
640
|
function setBillingMethod($billing_array) {
|
|
641
|
$this->_billing_method = $billing_array;
|
hpdl
|
439
|
642
|
|
|
643
|
$this->_calculate();
|
hpdl
|
421
|
644
|
}
|
|
645
|
|
|
646
|
function getBillingMethod($key = '') {
|
|
647
|
if (empty($key)) {
|
|
648
|
return $this->_billing_method;
|
|
649
|
}
|
|
650
|
|
|
651
|
return $this->_billing_method[$key];
|
|
652
|
}
|
|
653
|
|
|
654
|
function resetBillingMethod() {
|
|
655
|
$this->_billing_method = array();
|
hpdl
|
438
|
656
|
|
hpdl
|
439
|
657
|
$this->_calculate();
|
hpdl
|
421
|
658
|
}
|
|
659
|
|
|
660
|
function hasBillingMethod() {
|
|
661
|
return !empty($this->_billing_method);
|
|
662
|
}
|
|
663
|
|
hpdl
|
435
|
664
|
function getTaxingAddress($id = '') {
|
|
665
|
if ($this->getContentType() == 'virtual') {
|
|
666
|
return $this->getBillingAddress($id);
|
|
667
|
}
|
|
668
|
|
|
669
|
return $this->getShippingAddress($id);
|
|
670
|
}
|
|
671
|
|
hpdl
|
439
|
672
|
function addTaxAmount($amount) {
|
|
673
|
$this->_tax += $amount;
|
|
674
|
}
|
|
675
|
|
|
676
|
function addTaxGroup($group, $amount) {
|
|
677
|
if (isset($this->_tax_groups[$group])) {
|
|
678
|
$this->_tax_groups[$group] += $amount;
|
|
679
|
} else {
|
|
680
|
$this->_tax_groups[$group] = $amount;
|
|
681
|
}
|
|
682
|
}
|
|
683
|
|
|
684
|
function addToTotal($amount) {
|
|
685
|
$this->_total += $amount;
|
|
686
|
}
|
|
687
|
|
|
688
|
function getOrderTotals() {
|
|
689
|
return $this->_order_totals;
|
|
690
|
}
|
|
691
|
|
|
692
|
function getShippingBoxesWeight() {
|
|
693
|
return $this->_shipping_boxes_weight;
|
|
694
|
}
|
|
695
|
|
|
696
|
function numberOfShippingBoxes() {
|
|
697
|
return $this->_shipping_boxes;
|
|
698
|
}
|
|
699
|
|
hpdl
|
418
|
700
|
function _cleanUp() {
|
|
701
|
global $osC_Database, $osC_Customer;
|
|
702
|
|
hpdl
|
826
|
703
|
foreach ($this->_contents as $product_id_string => $data) {
|
hpdl
|
420
|
704
|
if ($data['quantity'] < 1) {
|
hpdl
|
826
|
705
|
unset($this->_contents[$product_id_string]);
|
hpdl
|
418
|
706
|
|
|
707
|
// remove from database
|
|
708
|
if ($osC_Customer->isLoggedOn()) {
|
|
709
|
$Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id and products_id = :products_id');
|
|
710
|
$Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
|
|
711
|
$Qdelete->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
826
|
712
|
$Qdelete->bindValue(':products_id', $product_id_string);
|
hpdl
|
418
|
713
|
$Qdelete->execute();
|
|
714
|
}
|
|
715
|
}
|
|
716
|
}
|
|
717
|
}
|
|
718
|
|
hpdl
|
439
|
719
|
function _calculate($set_shipping = true) {
|
hpdl
|
733
|
720
|
global $osC_Currencies, $osC_Tax, $osC_Weight, $osC_Shipping, $osC_OrderTotal;
|
hpdl
|
435
|
721
|
|
|
722
|
$this->_sub_total = 0;
|
hpdl
|
420
|
723
|
$this->_total = 0;
|
|
724
|
$this->_weight = 0;
|
hpdl
|
435
|
725
|
$this->_tax = 0;
|
|
726
|
$this->_tax_groups = array();
|
hpdl
|
439
|
727
|
$this->_cartID = $this->generateCartID();
|
hpdl
|
419
|
728
|
|
|
729
|
if ($this->hasContents()) {
|
hpdl
|
420
|
730
|
foreach ($this->_contents as $data) {
|
|
731
|
$products_weight = $osC_Weight->convert($data['weight'], $data['weight_class_id'], SHIPPING_WEIGHT_UNIT);
|
hpdl
|
435
|
732
|
$this->_weight += $products_weight * $data['quantity'];
|
hpdl
|
419
|
733
|
|
hpdl
|
435
|
734
|
$tax = $osC_Tax->getTaxRate($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id'));
|
|
735
|
$tax_description = $osC_Tax->getTaxRateDescription($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id'));
|
|
736
|
|
hpdl
|
748
|
737
|
$shown_price = $osC_Currencies->addTaxRateToPrice($data['final_price'], $tax, $data['quantity']);
|
hpdl
|
826
|
738
|
|
hpdl
|
435
|
739
|
$this->_sub_total += $shown_price;
|
|
740
|
$this->_total += $shown_price;
|
|
741
|
|
hpdl
|
500
|
742
|
if (DISPLAY_PRICE_WITH_TAX == '1') {
|
hpdl
|
435
|
743
|
$tax_amount = $shown_price - ($shown_price / (($tax < 10) ? '1.0' . str_replace('.', '', $tax) : '1.' . str_replace('.', '', $tax)));
|
|
744
|
} else {
|
|
745
|
$tax_amount = ($tax / 100) * $shown_price;
|
hpdl
|
826
|
746
|
|
|
747
|
$this->_total += $tax_amount;
|
hpdl
|
435
|
748
|
}
|
|
749
|
|
|
750
|
$this->_tax += $tax_amount;
|
|
751
|
|
|
752
|
if (isset($this->_tax_groups[$tax_description])) {
|
|
753
|
$this->_tax_groups[$tax_description] += $tax_amount;
|
|
754
|
} else {
|
|
755
|
$this->_tax_groups[$tax_description] = $tax_amount;
|
|
756
|
}
|
hpdl
|
419
|
757
|
}
|
|
758
|
}
|
hpdl
|
439
|
759
|
|
|
760
|
$this->_shipping_boxes_weight = $this->_weight;
|
|
761
|
$this->_shipping_boxes = 1;
|
|
762
|
|
|
763
|
if (SHIPPING_BOX_WEIGHT >= ($this->_shipping_boxes_weight * SHIPPING_BOX_PADDING/100)) {
|
|
764
|
$this->_shipping_boxes_weight = $this->_shipping_boxes_weight + SHIPPING_BOX_WEIGHT;
|
|
765
|
} else {
|
|
766
|
$this->_shipping_boxes_weight = $this->_shipping_boxes_weight + ($this->_shipping_boxes_weight * SHIPPING_BOX_PADDING/100);
|
|
767
|
}
|
|
768
|
|
|
769
|
if ($this->_shipping_boxes_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
|
|
770
|
$this->_shipping_boxes = ceil($this->_shipping_boxes_weight / SHIPPING_MAX_WEIGHT);
|
|
771
|
$this->_shipping_boxes_weight = $this->_shipping_boxes_weight / $this->_shipping_boxes;
|
|
772
|
}
|
|
773
|
|
|
774
|
if ($set_shipping === true) {
|
hpdl
|
809
|
775
|
if (!class_exists('osC_Shipping')) {
|
hpdl
|
439
|
776
|
include('includes/classes/shipping.php');
|
|
777
|
}
|
|
778
|
|
hpdl
|
809
|
779
|
if (!$this->hasShippingMethod() || ($this->getShippingMethod('is_cheapest') === true)) {
|
hpdl
|
439
|
780
|
$osC_Shipping = new osC_Shipping();
|
|
781
|
$this->setShippingMethod($osC_Shipping->getCheapestQuote(), false);
|
|
782
|
} else {
|
|
783
|
$osC_Shipping = new osC_Shipping($this->getShippingMethod('id'));
|
|
784
|
$this->setShippingMethod($osC_Shipping->getQuote(), false);
|
|
785
|
}
|
|
786
|
}
|
|
787
|
|
hpdl
|
809
|
788
|
if (!class_exists('osC_OrderTotal')) {
|
hpdl
|
439
|
789
|
include('includes/classes/order_total.php');
|
|
790
|
}
|
|
791
|
|
|
792
|
$osC_OrderTotal = new osC_OrderTotal();
|
|
793
|
$this->_order_totals = $osC_OrderTotal->getResult();
|
hpdl
|
419
|
794
|
}
|
|
795
|
|
hpdl
|
420
|
796
|
function _uasortProductsByDateAdded($a, $b) {
|
hpdl
|
418
|
797
|
if ($a['date_added'] == $b['date_added']) {
|
hpdl
|
420
|
798
|
return strnatcasecmp($a['name'], $b['name']);
|
hpdl
|
418
|
799
|
}
|
|