  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: shopping_cart.php 5 2005-01-31 01:40:15Z hpdl $ |
| |
| 3 | + | $Id: shopping_cart.php 19 2005-02-25 02:57:18Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
7 | 7 | | |
  |
8 | | - | Copyright (c) 2003 osCommerce |
| |
| 8 | + | Copyright (c) 2005 osCommerce |
|
9 | 9 | | |
| |
10 | 10 | | Released under the GNU General Public License |
| |
11 | 11 | | */ |
| |
|
|
 |
… |
|
18 | 18 | | } |
| |
19 | 19 | | |
| |
20 | 20 | | function restore_contents() { |
  |
21 | | - | global $osC_Customer; |
| |
| 21 | + | global $osC_Database, $osC_Customer; |
|
22 | 22 | | |
| |
23 | 23 | | if ($osC_Customer->isLoggedOn() == false) return false; |
| |
24 | 24 | | |
| |
|
|
 |
… |
|
27 | 27 | | reset($this->contents); |
| |
28 | 28 | | while (list($products_id, ) = each($this->contents)) { |
| |
29 | 29 | | $qty = $this->contents[$products_id]['qty']; |
  |
30 | | - | $product_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$osC_Customer->id . "' and products_id = '" . tep_db_input($products_id) . "'"); |
| |
31 | | - | if (!tep_db_num_rows($product_query)) { |
| |
32 | | - | tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$osC_Customer->id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "')"); |
| |
| 30 | + | |
| |
| 31 | + | $Qproduct = $osC_Database->query('select products_id from :table_customers_basket where customers_id = :customers_id and products_id = :products_id'); |
| |
| 32 | + | $Qproduct->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); |
| |
| 33 | + | $Qproduct->bindInt(':customers_id', $osC_Customer->id); |
| |
| 34 | + | $Qproduct->bindValue(':products_id', $products_id); |
| |
| 35 | + | $Qproduct->execute(); |
| |
| 36 | + | |
| |
| 37 | + | if ($Qproduct->numberOfRows() < 1) { |
| |
| 38 | + | $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, :customers_basket_date_added)'); |
| |
| 39 | + | $Qnew->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); |
| |
| 40 | + | $Qnew->bindInt(':customers_id', $osC_Customer->id); |
| |
| 41 | + | $Qnew->bindValue(':products_id', $products_id); |
| |
| 42 | + | $Qnew->bindInt(':customers_basket_quantity', $qty); |
| |
| 43 | + | $Qnew->bindValue(':customers_basket_date_added', date('Ymd')); |
| |
| 44 | + | $Qnew->execute(); |
| |
| 45 | + | |
|
33 | 46 | | if (isset($this->contents[$products_id]['attributes'])) { |
| |
34 | 47 | | reset($this->contents[$products_id]['attributes']); |
| |
35 | 48 | | while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { |
  |
36 | | - | tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int)$osC_Customer->id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "')"); |
| |
| 49 | + | $Qnew = $osC_Database->query('insert into :table_customers_basket_attributes (customers_id, products_id, products_options_id, products_options_value_id) values (:customers_id, :products_id, :products_options_id, :products_options_value_id)'); |
| |
| 50 | + | $Qnew->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES); |
| |
| 51 | + | $Qnew->bindInt(':customers_id', $osC_Customer->id); |
| |
| 52 | + | $Qnew->bindValue(':products_id', $products_id); |
| |
| 53 | + | $Qnew->bindInt(':products_options_id', $option); |
| |
| 54 | + | $Qnew->bindInt(':products_options_value_id', $value); |
| |
| 55 | + | $Qnew->execute(); |
|
37 | 56 | | } |
| |
38 | 57 | | } |
| |
39 | 58 | | } else { |
  |
40 | | - | tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $qty . "' where customers_id = '" . (int)$osC_Customer->id . "' and products_id = '" . tep_db_input($products_id) . "'"); |
| |
| 59 | + | $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'); |
| |
| 60 | + | $Qupdate->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); |
| |
| 61 | + | $Qupdate->bindInt(':customers_basket_quantity', $qty); |
| |
| 62 | + | $Qupdate->bindInt(':customers_id', $osC_Customer->id); |
| |
| 63 | + | $Qupdate->bindValue(':products_id', $products_id); |
| |
| 64 | + | $Qupdate->execute(); |
|
41 | 65 | | } |
| |
42 | 66 | | } |
| |
43 | 67 | | } |
| |
44 | 68 | | |
| |
45 | 69 | | // reset per-session cart contents, but not the database contents |
| |
46 | 70 | | $this->reset(false); |
| |
47 | 71 | | |
  |
48 | | - | $products_query = tep_db_query("select products_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$osC_Customer->id . "'"); |
| |
49 | | - | while ($products = tep_db_fetch_array($products_query)) { |
| |
50 | | - | $this->contents[$products['products_id']] = array('qty' => $products['customers_basket_quantity']); |
| |
| 72 | + | $Qproducts = $osC_Database->query('select products_id, customers_basket_quantity from :table_customers_basket where customers_id = :customers_id'); |
| |
| 73 | + | $Qproducts->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); |
| |
| 74 | + | $Qproducts->bindInt(':customers_id', $osC_Customer->id); |
| |
| 75 | + | $Qproducts->execute(); |
| |
| 76 | + | |
| |
| 77 | + | while ($Qproducts->next()) { |
| |
| 78 | + | $this->contents[$Qproducts->value('products_id')] = array('qty' => $Qproducts->valueInt('customers_basket_quantity')); |
|
51 | 79 | | // attributes |
  |
52 | | - | $attributes_query = tep_db_query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$osC_Customer->id . "' and products_id = '" . tep_db_input($products['products_id']) . "'"); |
| |
53 | | - | while ($attributes = tep_db_fetch_array($attributes_query)) { |
| |
54 | | - | $this->contents[$products['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id']; |
| |
| 80 | + | $Qattributes = $osC_Database->query('select products_options_id, products_options_value_id from :table_customers_basket_attributes where customers_id = :customers_id and products_id = :products_id'); |
| |
| 81 | + | $Qattributes->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES); |
| |
| 82 | + | $Qattributes->bindInt(':customers_id', $osC_Customer->id); |
| |
| 83 | + | $Qattributes->bindValue(':products_id', $Qproducts->value('products_id')); |
| |
| 84 | + | $Qattributes->execute(); |
| |
| 85 | + | |
| |
| 86 | + | while ($Qattributes->next()) { |
| |
| 87 | + | $this->contents[$Qproducts->value('products_id')]['attributes'][$Qattributes->valueInt('products_options_id')] = $Qattributes->valueInt('products_options_value_id'); |
|
55 | 88 | | } |
| |
56 | 89 | | } |
| |
57 | 90 | | |
| |
58 | 91 | | $this->cleanup(); |
| |
59 | 92 | | } |
| |
60 | 93 | | |
| |
61 | 94 | | function reset($reset_database = false) { |
  |
62 | | - | global $osC_Session, $osC_Customer; |
| |
| 95 | + | global $osC_Database, $osC_Session, $osC_Customer; |
|
63 | 96 | | |
| |
64 | 97 | | $this->contents = array(); |
| |
65 | 98 | | $this->total = 0; |
| |
66 | 99 | | $this->weight = 0; |
| |
67 | 100 | | $this->content_type = false; |
| |
68 | 101 | | |
| |
69 | 102 | | if (($reset_database == true) && $osC_Customer->isLoggedOn()) { |
  |
70 | | - | tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$osC_Customer->id . "'"); |
| |
71 | | - | tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$osC_Customer->id . "'"); |
| |
| 103 | + | $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id'); |
| |
| 104 | + | $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); |
| |
| 105 | + | $Qdelete->bindInt(':customers_id', $osC_Customer->id); |
| |
| 106 | + | $Qdelete->execute(); |
| |
| 107 | + | |
| |
| 108 | + | $Qdelete = $osC_Database->query('delete from :table_customers_basket_attributes where customers_id = :customers_id'); |
| |
| 109 | + | $Qdelete->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES); |
| |
| 110 | + | $Qdelete->bindInt(':customers_id', $osC_Customer->id); |
| |
| 111 | + | $Qdelete->execute(); |
|
72 | 112 | | } |
| |
73 | 113 | | |
| |
74 | 114 | | unset($this->cartID); |
| |
75 | 115 | | $osC_Session->remove('cartID'); |
| |
76 | 116 | | } |
| |
77 | 117 | | |
| |
78 | 118 | | function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) { |
  |
79 | | - | global $osC_Session, $osC_Customer; |
| |
| 119 | + | global $osC_Database, $osC_Session, $osC_Customer; |
|
80 | 120 | | |
| |
81 | 121 | | $products_id_string = tep_get_uprid($products_id, $attributes); |
| |
82 | 122 | | $products_id = tep_get_prid($products_id_string); |
| |
83 | 123 | | |
| |
84 | 124 | | if (is_numeric($products_id) && is_numeric($qty)) { |
  |
85 | | - | $check_product_query = tep_db_query("select products_status from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"); |
| |
86 | | - | $check_product = tep_db_fetch_array($check_product_query); |
| |
| 125 | + | $Qcheck = $osC_Database->query('select products_status from :table_products where products_id = :products_id'); |
| |
| 126 | + | $Qcheck->bindTable(':table_products', TABLE_PRODUCTS); |
| |
| 127 | + | $Qcheck->bindInt(':products_id', $products_id); |
| |
| 128 | + | $Qcheck->execute(); |
|
87 | 129 | | |
  |
88 | | - | if (($check_product !== false) && ($check_product['products_status'] == '1')) { |
| |
| 130 | + | if (($check_product !== false) && ($Qcheck->valueInt('products_status') == '1')) { |
|
89 | 131 | | if ($notify == true) { |
| |
90 | 132 | | $osC_Session->set('new_products_id_in_cart', $products_id_string); |
| |
91 | 133 | | } |
| |
|
|
 |
… |
|
95 | 137 | | } else { |
| |
96 | 138 | | $this->contents[$products_id_string] = array('qty' => $qty); |
| |
97 | 139 | | // insert into database |
  |
98 | | - | if ($osC_Customer->isLoggedOn()) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$osC_Customer->id . "', '" . tep_db_input($products_id_string) . "', '" . (int)$qty . "', '" . date('Ymd') . "')"); |
| |
| 140 | + | if ($osC_Customer->isLoggedOn()) { |
| |
| 141 | + | $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, :customers_basket_date_added)'); |
| |
| 142 | + | $Qnew->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); |
| |
| 143 | + | $Qnew->bindInt(':customers_id', $osC_Customer->id); |
| |
| 144 | + | $Qnew->bindValue(':products_id', $products_id_string); |
| |
| 145 | + | $Qnew->bindInt(':customers_basket_quantity', $qty); |
| |
| 146 | + | $Qnew->bindValue(':customers_basket_date_added', date('Ymd')); |
| |
| 147 | + | $Qnew->execute(); |
| |
| 148 | + | } |
|
99 | 149 | | |
| |
100 | 150 | | if (is_array($attributes)) { |
| |
101 | 151 | | reset($attributes); |
| |
102 | 152 | | while (list($option, $value) = each($attributes)) { |
| |
103 | 153 | | $this->contents[$products_id_string]['attributes'][$option] = $value; |
| |
104 | 154 | | // insert into database |
  |
105 | | - | if ($osC_Customer->isLoggedOn()) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int)$osC_Customer->id . "', '" . tep_db_input($products_id_string) . "', '" . (int)$option . "', '" . (int)$value . "')"); |
| |
| 155 | + | if ($osC_Customer->isLoggedOn()) { |
| |
| 156 | + | $Qnew = $osC_Database->query('insert into :table_customers_basket_attributes (customers_id, products_id, products_options_id, products_options_value_id) values (:customers_id, :products_id, :products_options_id, :products_options_value_id)'); |
| |
| 157 | + | $Qnew->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES); |
| |
| 158 | + | $Qnew->bindInt(':customers_id', $osC_Customer->id); |
| |
| 159 | + | $Qnew->bindValue(':products_id', $products_id_string); |
| |
| 160 | + | $Qnew->bindInt(':products_options_id', $option); |
| |
| 161 | + | $Qnew->bindInt(':products_options_value_id', $value); |
| |
| 162 | + | $Qnew->execute(); |
| |
| 163 | + | } |
|
106 | 164 | | } |
| |
107 | 165 | | } |
| |
108 | 166 | | } |
| |
|
|
 |
… |
|
116 | 174 | | } |
| |
117 | 175 | | |
| |
118 | 176 | | function update_quantity($products_id, $quantity = '', $attributes = '') { |
  |
119 | | - | global $osC_Customer; |
| |
| 177 | + | global $osC_Database, $osC_Customer; |
|
120 | 178 | | |
| |
121 | 179 | | $products_id_string = tep_get_uprid($products_id, $attributes); |
| |
122 | 180 | | $products_id = tep_get_prid($products_id_string); |
| |
123 | 181 | | |
| |
124 | 182 | | if (is_numeric($products_id) && isset($this->contents[$products_id_string]) && is_numeric($quantity)) { |
| |
125 | 183 | | $this->contents[$products_id_string] = array('qty' => $quantity); |
| |
126 | 184 | | // update database |
  |
127 | | - | if ($osC_Customer->isLoggedOn()) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . (int)$quantity . "' where customers_id = '" . (int)$osC_Customer->id . "' and products_id = '" . tep_db_input($products_id_string) . "'"); |
| |
| 185 | + | if ($osC_Customer->isLoggedOn()) { |
| |
| 186 | + | $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'); |
| |
| 187 | + | $Qupdate->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); |
| |
| 188 | + | $Qupdate->bindInt(':customers_basket_quantity', $quantity); |
| |
| 189 | + | $Qupdate->bindInt(':customers_id', $osC_Customer->id); |
| |
| 190 | + | $Qupdate->bindValue(':products_id', $products_id_string); |
| |
| 191 | + | $Qupdate->execute(); |
| |
| 192 | + | } |
|
128 | 193 | | |
| |
129 | 194 | | if (is_array($attributes)) { |
| |
130 | 195 | | reset($attributes); |
| |
131 | 196 | | while (list($option, $value) = each($attributes)) { |
| |
132 | 197 | | $this->contents[$products_id_string]['attributes'][$option] = $value; |
| |
133 | 198 | | // update database |
  |
134 | | - | if ($osC_Customer->isLoggedOn()) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "' where customers_id = '" . (int)$osC_Customer->id . "' and products_id = '" . tep_db_input($products_id_string) . "' and products_options_id = '" . (int)$option . "'"); |
| |
| 199 | + | if ($osC_Customer->isLoggedOn()) { |
| |
| 200 | + | $Qupdate = $osC_Database->query('update :table_customers_basket_attributes set products_options_value_id = :products_options_value_id where customers_id = :customers_id and products_id = :products_id and products_options_id = :products_options_id'); |
| |
| 201 | + | $Qupdate->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES); |
| |
| 202 | + | $Qupdate->bindInt(':products_options_value_id', $value); |
| |
| 203 | + | $Qupdate->bindInt(':customers_id', $osC_Customer->id); |
| |
| 204 | + | $Qupdate->bindValue(':products_id', $products_id_string); |
| |
| 205 | + | $Qupdate->bindInt(':products_options_id', $option); |
| |
| 206 | + | $Qupdate->execute(); |
| |
| 207 | + | } |
|
135 | 208 | | } |
| |
136 | 209 | | } |
| |
137 | 210 | | } |
| |
138 | 211 | | } |
| |
139 | 212 | | |
| |
140 | 213 | | function cleanup() { |
  |
141 | | - | global $osC_Customer; |
| |
| 214 | + | global $osC_Database, $osC_Customer; |
|
142 | 215 | | |
| |
143 | 216 | | reset($this->contents); |
| |
144 | 217 | | while (list($key,) = each($this->contents)) { |
| |
145 | 218 | | if ($this->contents[$key]['qty'] < 1) { |
| |
146 | 219 | | unset($this->contents[$key]); |
| |
147 | 220 | | // remove from database |
| |
148 | 221 | | if ($osC_Customer->isLoggedOn()) { |
  |
149 | | - | tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$osC_Customer->id . "' and products_id = '" . tep_db_input($key) . "'"); |
| |
150 | | - | tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$osC_Customer->id . "' and products_id = '" . tep_db_input($key) . "'"); |
| |
| 222 | + | $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id and products_id = :products_id'); |
| |
| 223 | + | $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); |
| |
| 224 | + | $Qdelete->bindInt(':customers_id', $osC_Customer->id); |
| |
| 225 | + | $Qdelete->bindValue(':products_id', $key); |
| |
| 226 | + | $Qdelete->execute(); |
| |
| 227 | + | |
| |
| 228 | + | $Qdelete = $osC_Database->query('delete from :table_customers_basket_attributes where customers_id = :customers_id and products_id = :products_id'); |
| |
| 229 | + | $Qdelete->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES); |
| |
| 230 | + | $Qdelete->bindInt(':customers_id', $osC_Customer->id); |
| |
| 231 | + | $Qdelete->bindValue(':products_id', $key); |
| |
| 232 | + | $Qdelete->execute(); |
|
151 | 233 | | } |
| |
152 | 234 | | } |
| |
153 | 235 | | } |
| |
|
|
 |
… |
|
182 | 264 | | } |
| |
183 | 265 | | |
| |
184 | 266 | | function remove($products_id) { |
  |
185 | | - | global $osC_Customer; |
| |
| 267 | + | global $osC_Database, $osC_Customer; |
|
186 | 268 | | |
| |
187 | 269 | | unset($this->contents[$products_id]); |
| |
188 | 270 | | // remove from database |
| |
189 | 271 | | if ($osC_Customer->isLoggedOn()) { |
  |
190 | | - | tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$osC_Customer->id . "' and products_id = '" . tep_db_input($products_id) . "'"); |
| |
191 | | - | tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$osC_Customer->id . "' and products_id = '" . tep_db_input($products_id) . "'"); |
| |
| 272 | + | $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id and products_id = :products_id'); |
| |
| 273 | + | $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET); |
| |
| 274 | + | $Qdelete->bindInt(':customers_id', $osC_Customer->id); |
| |
| 275 | + | $Qdelete->bindValue(':products_id', $products_id); |
| |
| 276 | + | $Qdelete->execute(); |
| |
| 277 | + | |
| |
| 278 | + | $Qdelete = $osC_Database->query('delete from :table_customers_basket_attributes where customers_id = :customers_id and products_id = :products_id'); |
| |
| 279 | + | $Qdelete->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES); |
| |
| 280 | + | $Qdelete->bindInt(':customers_id', $osC_Customer->id); |
| |
| 281 | + | $Qdelete->bindValue(':products_id', $products_id); |
| |
| 282 | + | $Qdelete->execute(); |
|
192 | 283 | | } |
| |
193 | 284 | | |
| |
194 | 285 | | // assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure |
| |
|
|
 |
… |
|
212 | 303 | | } |
| |
213 | 304 | | |
| |
214 | 305 | | function calculate() { |
  |
215 | | - | global $osC_Tax, $osC_Weight; |
| |
| 306 | + | global $osC_Database, $osC_Tax, $osC_Weight; |
|
216 | 307 | | |
| |
217 | 308 | | $this->total = 0; |
| |
218 | 309 | | $this->weight = 0; |
| |
|
|
 |
… |
|
223 | 314 | | $qty = $this->contents[$products_id]['qty']; |
| |
224 | 315 | | |
| |
225 | 316 | | // products price |
  |
226 | | - | $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight, products_weight_class from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"); |
| |
227 | | - | if ($product = tep_db_fetch_array($product_query)) { |
| |
228 | | - | $prid = $product['products_id']; |
| |
229 | | - | $products_tax = $osC_Tax->getTaxRate($product['products_tax_class_id']); |
| |
230 | | - | $products_price = $product['products_price']; |
| |
| 317 | + | $Qproduct = $osC_Database->query('select products_id, products_price, products_tax_class_id, products_weight, products_weight_class from :table_products where products_id = :products_id'); |
| |
| 318 | + | $Qproduct->bindTable(':table_products', TABLE_PRODUCTS); |
| |
| 319 | + | $Qproduct->bindInt(':products_id', $products_id); |
| |
| 320 | + | $Qproduct->execute(); |
|
231 | 321 | | |
  |
232 | | - | $products_weight = $osC_Weight->convert($product['products_weight'], $product['products_weight_class'], SHIPPING_WEIGHT_UNIT); |
| |
| 322 | + | if ($Qproduct->numberOfRows()) { |
| |
| 323 | + | $prid = $Qproduct->valueInt('products_id'); |
| |
| 324 | + | $products_tax = $osC_Tax->getTaxRate($Qproduct->valueInt('products_tax_class_id')); |
| |
| 325 | + | $products_price = $Qproduct->value('products_price'); |
|
233 | 326 | | |
  |
234 | | - | $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'"); |
| |
235 | | - | if (tep_db_num_rows ($specials_query)) { |
| |
236 | | - | $specials = tep_db_fetch_array($specials_query); |
| |
237 | | - | $products_price = $specials['specials_new_products_price']; |
| |
| 327 | + | $products_weight = $osC_Weight->convert($Qproduct->value('products_weight'), $Qproduct->valueInt('products_weight_class'), SHIPPING_WEIGHT_UNIT); |
| |
| 328 | + | |
| |
| 329 | + | $Qspecials = $osC_Database->query('select specials_new_products_price from :table_specials where products_id = :products_id and status = :status'); |
| |
| 330 | + | $Qspecials->bindTable(':table_specials', TABLE_SPECIALS); |
| |
| 331 | + | $Qspecials->bindInt(':products_id', $prid); |
| |
| 332 | + | $Qspecials->bindInt(':status', 1); |
| |
| 333 | + | $Qspecials->execute(); |
| |
| 334 | + | |
| |
| 335 | + | if ($Qspecials->numberOfRows()) { |
| |
| 336 | + | $products_price = $Qspecials->value('specials_new_products_price'); |
|
238 | 337 | | } |
| |
239 | 338 | | |
| |
240 | 339 | | $this->total += tep_add_tax($products_price, $products_tax) * $qty; |
| |
|
|
 |
… |
|
245 | 344 | | if (isset($this->contents[$products_id]['attributes'])) { |
| |
246 | 345 | | reset($this->contents[$products_id]['attributes']); |
| |
247 | 346 | | while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { |
  |
248 | | - | $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'"); |
| |
249 | | - | $attribute_price = tep_db_fetch_array($attribute_price_query); |
| |
250 | | - | if ($attribute_price['price_prefix'] == '+') { |
| |
251 | | - | $this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax); |
| |
| 347 | + | $Qattributes = $osC_Database->query('select options_values_price, price_prefix from :table_products_attributes where products_id = :products_id and options_id = :options_id and options_values_id = :options_values_id'); |
| |
| 348 | + | $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); |
| |
| 349 | + | $Qattributes->bindInt(':products_id', $prid); |
| |
| 350 | + | $Qattributes->bindInt(':options_id', $option); |
| |
| 351 | + | $Qattributes->bindInt(':options_values_id', $value); |
| |
| 352 | + | $Qattributes->execute(); |
| |
| 353 | + | |
| |
| 354 | + | if ($Qattributes->value('price_prefix') == '+') { |
| |
| 355 | + | $this->total += $qty * tep_add_tax($Qattributes->value('options_values_price'), $products_tax); |
|
252 | 356 | | } else { |
  |
253 | | - | $this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax); |
| |
| 357 | + | $this->total -= $qty * tep_add_tax($Qattributes->value('options_values_price'), $products_tax); |
|
254 | 358 | | } |
| |
255 | 359 | | } |
| |
256 | 360 | | } |
| |
257 | 361 | | } |
| |
258 | 362 | | } |
| |
259 | 363 | | |
| |
260 | 364 | | function attributes_price($products_id) { |
  |
| 365 | + | global $osC_Database; |
| |
| 366 | + | |
|
261 | 367 | | $attributes_price = 0; |
| |
262 | 368 | | |
| |
263 | 369 | | if (isset($this->contents[$products_id]['attributes'])) { |
| |
264 | 370 | | reset($this->contents[$products_id]['attributes']); |
| |
265 | 371 | | while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { |
  |
266 | | - | $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'"); |
| |
267 | | - | $attribute_price = tep_db_fetch_array($attribute_price_query); |
| |
268 | | - | if ($attribute_price['price_prefix'] == '+') { |
| |
269 | | - | $attributes_price += $attribute_price['options_values_price']; |
| |
| 372 | + | $Qattributes = $osC_Database->query('select options_values_price, price_prefix from :table_products_attributes where products_id = :products_id and options_id = :options_id and options_values_id = :options_values_id'); |
| |
| 373 | + | $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); |
| |
| 374 | + | $Qattributes->bindInt(':products_id', $products_id); |
| |
| 375 | + | $Qattributes->bindInt(':options_id', $option); |
| |
| 376 | + | $Qattributes->bindInt(':options_values_id', $value); |
| |
| 377 | + | $Qattributes->execute(); |
| |
| 378 | + | |
| |
| 379 | + | if ($Qattributes->value('price_prefix') == '+') { |
| |
| 380 | + | $attributes_price += $Qattributes->value('options_values_price'); |
|
270 | 381 | | } else { |
  |
271 | | - | $attributes_price -= $attribute_price['options_values_price']; |
| |
| 382 | + | $attributes_price -= $Qattributes->value('options_values_price'); |
|
272 | 383 | | } |
| |
273 | 384 | | } |
| |
274 | 385 | | } |
| |
|
|
 |
… |
|
277 | 388 | | } |
| |
278 | 389 | | |
| |
279 | 390 | | function get_products() { |
  |
280 | | - | global $osC_Session; |
| |
| 391 | + | global $osC_Database, $osC_Session; |
|
281 | 392 | | |
| |
282 | 393 | | if (!is_array($this->contents)) return false; |
| |
283 | 394 | | |
| |
284 | 395 | | $products_array = array(); |
| |
285 | 396 | | reset($this->contents); |
| |
286 | 397 | | while (list($products_id, ) = each($this->contents)) { |
  |
287 | | - | $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$osC_Session->value('languages_id') . "'"); |
| |
288 | | - | if ($products = tep_db_fetch_array($products_query)) { |
| |
289 | | - | $prid = $products['products_id']; |
| |
290 | | - | $products_price = $products['products_price']; |
| |
| 398 | + | $Qproducts = $osC_Database->query('select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from :table_products p, :table_products_description pd where p.products_id = :products_id and pd.products_id = p.products_id and pd.language_id = :language_id'); |
| |
| 399 | + | $Qproducts->bindTable(':table_products', TABLE_PRODUCTS); |
| |
| 400 | + | $Qproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION); |
| |
| 401 | + | $Qproducts->bindInt(':products_id', $products_id); |
| |
| 402 | + | $Qproducts->bindInt(':language_id', $osC_Session->value('languages_id')); |
| |
| 403 | + | $Qproducts->execute(); |
|
291 | 404 | | |
  |
292 | | - | $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'"); |
| |
293 | | - | if (tep_db_num_rows($specials_query)) { |
| |
294 | | - | $specials = tep_db_fetch_array($specials_query); |
| |
295 | | - | $products_price = $specials['specials_new_products_price']; |
| |
| 405 | + | if ($Qproducts->numberOfRows()) { |
| |
| 406 | + | $prid = $Qproducts->valueInt('products_id'); |
| |
| 407 | + | $products_price = $Qproducts->value('products_price'); |
| |
| 408 | + | |
| |
| 409 | + | $Qspecials = $osC_Database->query('select specials_new_products_price from :table_specials where products_id = :products_id and status = :status'); |
| |
| 410 | + | $Qspecials->bindTable(':table_specials', TABLE_SPECIALS); |
| |
| 411 | + | $Qspecials->bindInt(':products_id', $prid); |
| |
| 412 | + | $Qspecials->bindInt(':status', 1); |
| |
| 413 | + | $Qspecials->execute(); |
| |
| 414 | + | |
| |
| 415 | + | if ($Qspecials->numberOfRows()) { |
| |
| 416 | + | $products_price = $Qspecials->value('specials_new_products_price'); |
|
296 | 417 | | } |
| |
297 | 418 | | |
| |
298 | 419 | | $products_array[] = array('id' => $products_id, |
  |
299 | | - | 'name' => $products['products_name'], |
| |
300 | | - | 'model' => $products['products_model'], |
| |
301 | | - | 'image' => $products['products_image'], |
| |
| 420 | + | 'name' => $Qproducts->value('products_name'), |
| |
| 421 | + | 'model' => $Qproducts->value('products_model'), |
| |
| 422 | + | 'image' => $Qproducts->value('products_image'), |
|
302 | 423 | | 'price' => $products_price, |
| |
303 | 424 | | 'quantity' => $this->contents[$products_id]['qty'], |
  |
304 | | - | 'weight' => $products['products_weight'], |
| |
| 425 | + | 'weight' => $Qproducts->value('products_weight'), |
|
305 | 426 | | 'final_price' => ($products_price + $this->attributes_price($products_id)), |
  |
306 | | - | 'tax_class_id' => $products['products_tax_class_id'], |
| |
| 427 | + | 'tax_class_id' => $Qproducts->valueInt('products_tax_class_id'), |
|
307 | 428 | | 'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : '')); |
| |
308 | 429 | | } |
| |
309 | 430 | | } |
| |
|
|
 |
… |
|
328 | 449 | | } |
| |
329 | 450 | | |
| |
330 | 451 | | function get_content_type() { |
  |
| 452 | + | global $osC_Database; |
| |
| 453 | + | |
|
331 | 454 | | $this->content_type = false; |
| |
332 | 455 | | |
| |
333 | 456 | | if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) { |
| |
|
|
 |
… |
|
336 | 459 | | if (isset($this->contents[$products_id]['attributes'])) { |
| |
337 | 460 | | reset($this->contents[$products_id]['attributes']); |
| |
338 | 461 | | while (list(, $value) = each($this->contents[$products_id]['attributes'])) { |
  |
339 | | - | $virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$products_id . "' and pa.options_values_id = '" . (int)$value . "' and pa.products_attributes_id = pad.products_attributes_id"); |
| |
340 | | - | $virtual_check = tep_db_fetch_array($virtual_check_query); |
| |
| 462 | + | $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'); |
| |
| 463 | + | $Qcheck->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); |
| |
| 464 | + | $Qcheck->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD); |
| |
| 465 | + | $Qcheck->bindInt(':products_id', $products_id); |
| |
| 466 | + | $Qcheck->bindInt(':options_values_id', $value); |
| |
| 467 | + | $Qcheck->execute(); |
|
341 | 468 | | |
  |
342 | | - | if ($virtual_check['total'] > 0) { |
| |
| 469 | + | if ($Qcheck->valueInt('total') > 0) { |
  |
343 | 470 | | switch ($this->content_type) { |
| |
344 | 471 | | case 'physical': |
| |
345 | 472 | | $this->content_type = 'mixed'; |