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