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