  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: order.php 151 2005-08-02 14:33:25Z mattice $ |
| |
| 3 | + | $Id: order.php 368 2005-12-22 16:27:23Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
|
|
 |
… |
|
13 | 13 | | class order { |
| |
14 | 14 | | var $info, $totals, $products, $customer, $delivery, $content_type; |
| |
15 | 15 | | |
  |
| 16 | + | /* Private variables */ |
| |
| 17 | + | |
| |
| 18 | + | var $_id; |
| |
| 19 | + | |
| |
| 20 | + | /* Class constructor */ |
| |
| 21 | + | |
|
16 | 22 | | function order($order_id = '') { |
  |
| 23 | + | if (is_numeric($order_id)) { |
| |
| 24 | + | $this->_id = $order_id; |
| |
| 25 | + | } |
| |
| 26 | + | |
|
17 | 27 | | $this->info = array(); |
| |
18 | 28 | | $this->totals = array(); |
| |
19 | 29 | | $this->products = array(); |
| |
|
|
 |
… |
|
27 | 37 | | } |
| |
28 | 38 | | } |
| |
29 | 39 | | |
  |
| 40 | + | /* Public methods */ |
| |
| 41 | + | |
| |
| 42 | + | function &getListing($limit = null, $page_keyword = 'page') { |
| |
| 43 | + | global $osC_Database, $osC_Customer; |
| |
| 44 | + | |
| |
| 45 | + | $Qorders = $osC_Database->query('select o.orders_id, o.date_purchased, o.delivery_name, o.delivery_country, o.billing_name, o.billing_country, ot.text as order_total, s.orders_status_name from :table_orders o, :table_orders_total ot, :table_orders_status s where o.customers_id = :customers_id and o.orders_id = ot.orders_id and ot.class = "ot_total" and o.orders_status = s.orders_status_id and s.language_id = :language_id order by orders_id desc'); |
| |
| 46 | + | $Qorders->bindTable(':table_orders', TABLE_ORDERS); |
| |
| 47 | + | $Qorders->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL); |
| |
| 48 | + | $Qorders->bindTable(':table_orders_status', TABLE_ORDERS_STATUS); |
| |
| 49 | + | $Qorders->bindInt(':customers_id', $osC_Customer->getID()); |
| |
| 50 | + | $Qorders->bindInt(':language_id', $_SESSION['languages_id']); |
| |
| 51 | + | |
| |
| 52 | + | if (is_numeric($limit)) { |
| |
| 53 | + | $Qorders->setBatchLimit(isset($_GET[$page_keyword]) && is_numeric($_GET[$page_keyword]) ? $_GET[$page_keyword] : 1, $limit); |
| |
| 54 | + | } |
| |
| 55 | + | |
| |
| 56 | + | $Qorders->execute(); |
| |
| 57 | + | |
| |
| 58 | + | return $Qorders; |
| |
| 59 | + | } |
| |
| 60 | + | |
| |
| 61 | + | function &getStatusListing($id = null) { |
| |
| 62 | + | global $osC_Database; |
| |
| 63 | + | |
| |
| 64 | + | if ( ($id === null) && isset($this) ) { |
| |
| 65 | + | $id = $this->_id; |
| |
| 66 | + | } |
| |
| 67 | + | |
| |
| 68 | + | $Qstatus = $osC_Database->query('select os.orders_status_name, osh.date_added, osh.comments from :table_orders_status os, :table_orders_status_history osh where osh.orders_id = :orders_id and osh.orders_status_id = os.orders_status_id and os.language_id = :language_id order by osh.date_added'); |
| |
| 69 | + | $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS); |
| |
| 70 | + | $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY); |
| |
| 71 | + | $Qstatus->bindInt(':orders_id', $id); |
| |
| 72 | + | $Qstatus->bindInt(':language_id', $_SESSION['languages_id']); |
| |
| 73 | + | |
| |
| 74 | + | return $Qstatus; |
| |
| 75 | + | } |
| |
| 76 | + | |
| |
| 77 | + | function getCustomerID($id = null) { |
| |
| 78 | + | global $osC_Database; |
| |
| 79 | + | |
| |
| 80 | + | if ( ($id === null) && isset($this) ) { |
| |
| 81 | + | $id = $this->_id; |
| |
| 82 | + | } |
| |
| 83 | + | |
| |
| 84 | + | $Qcustomer = $osC_Database->query('select customers_id from :table_orders where orders_id = :orders_id'); |
| |
| 85 | + | $Qcustomer->bindTable(':table_orders', TABLE_ORDERS); |
| |
| 86 | + | $Qcustomer->bindInt(':orders_id', $id); |
| |
| 87 | + | $Qcustomer->execute(); |
| |
| 88 | + | |
| |
| 89 | + | return $Qcustomer->valueInt('customers_id'); |
| |
| 90 | + | } |
| |
| 91 | + | |
| |
| 92 | + | function numberOfEntries() { |
| |
| 93 | + | global $osC_Database, $osC_Customer; |
| |
| 94 | + | static $total_entries; |
| |
| 95 | + | |
| |
| 96 | + | if (is_numeric($total_entries) === false) { |
| |
| 97 | + | if ($osC_Customer->isLoggedOn()) { |
| |
| 98 | + | $Qorders = $osC_Database->query('select count(*) as total from :table_orders where customers_id = :customers_id'); |
| |
| 99 | + | $Qorders->bindTable(':table_orders', TABLE_ORDERS); |
| |
| 100 | + | $Qorders->bindInt(':customers_id', $osC_Customer->getID()); |
| |
| 101 | + | $Qorders->execute(); |
| |
| 102 | + | |
| |
| 103 | + | $total_entries = $Qorders->valueInt('total'); |
| |
| 104 | + | } else { |
| |
| 105 | + | $total_entries = 0; |
| |
| 106 | + | } |
| |
| 107 | + | } |
| |
| 108 | + | |
| |
| 109 | + | return $total_entries; |
| |
| 110 | + | } |
| |
| 111 | + | |
| |
| 112 | + | function numberOfProducts($id = null) { |
| |
| 113 | + | global $osC_Database; |
| |
| 114 | + | |
| |
| 115 | + | if ( ($id === null) && isset($this) ) { |
| |
| 116 | + | $id = $this->_id; |
| |
| 117 | + | } |
| |
| 118 | + | |
| |
| 119 | + | $Qproducts = $osC_Database->query('select count(*) as total from :table_orders_products where orders_id = :orders_id'); |
| |
| 120 | + | $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS); |
| |
| 121 | + | $Qproducts->bindInt(':orders_id', $id); |
| |
| 122 | + | $Qproducts->execute(); |
| |
| 123 | + | |
| |
| 124 | + | return $Qproducts->valueInt('total'); |
| |
| 125 | + | } |
| |
| 126 | + | |
| |
| 127 | + | |
| |
| 128 | + | |
|
30 | 129 | | function query($order_id) { |
  |
31 | | - | global $osC_Database, $osC_Session; |
| |
| 130 | + | global $osC_Database; |
|
32 | 131 | | |
| |
33 | 132 | | $Qorder = $osC_Database->query('select customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, currency, currency_value, date_purchased, orders_status, last_modified from :table_orders where orders_id = :orders_id'); |
| |
34 | 133 | | $Qorder->bindTable(':table_orders', TABLE_ORDERS); |
| |
|
|
 |
… |
|
63 | 162 | | $Qstatus = $osC_Database->query('select orders_status_name from :table_orders_status where orders_status_id = :orders_status_id and language_id = :language_id'); |
| |
64 | 163 | | $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS); |
| |
65 | 164 | | $Qstatus->bindInt(':orders_status_id', $Qorder->valueInt('orders_status')); |
  |
66 | | - | $Qstatus->bindInt(':language_id', $osC_Session->value('languages_id')); |
| |
| 165 | + | $Qstatus->bindInt(':language_id', $_SESSION['languages_id']); |
|
67 | 166 | | $Qstatus->execute(); |
| |
68 | 167 | | |
| |
69 | 168 | | $this->info = array('currency' => $Qorder->value('currency'), |
| |
|
|
 |
… |
|
158 | 257 | | } |
| |
159 | 258 | | |
| |
160 | 259 | | function cart() { |
  |
161 | | - | global $osC_Database, $osC_Session, $osC_Customer, $osC_Tax, $cart, $osC_Currencies; |
| |
| 260 | + | global $osC_Database, $osC_Customer, $osC_Tax, $osC_Currencies; |
|
162 | 261 | | |
  |
163 | | - | $this->content_type = $cart->get_content_type(); |
| |
| 262 | + | $this->content_type = $_SESSION['cart']->get_content_type(); |
|
164 | 263 | | |
  |
165 | | - | $shipping =& $osC_Session->value('shipping'); |
| |
166 | | - | $payment =& $osC_Session->value('payment'); |
| |
| 264 | + | $shipping =& $_SESSION['shipping']; |
| |
| 265 | + | $payment =& $_SESSION['payment']; |
|
167 | 266 | | |
| |
168 | 267 | | $Qcustomer = $osC_Database->query('select c.customers_firstname, c.customers_lastname, c.customers_telephone, c.customers_email_address, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, co.countries_id, co.countries_name, co.countries_iso_code_2, co.countries_iso_code_3, co.address_format_id, ab.entry_state from :table_customers c, :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) left join :table_countries co on (ab.entry_country_id = co.countries_id) where c.customers_id = :customers_id and ab.customers_id = :customers_id and c.customers_default_address_id = ab.address_book_id'); |
| |
169 | 268 | | $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS); |
| |
170 | 269 | | $Qcustomer->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); |
| |
171 | 270 | | $Qcustomer->bindTable(':table_zones', TABLE_ZONES); |
| |
172 | 271 | | $Qcustomer->bindTable(':table_countries', TABLE_COUNTRIES); |
  |
173 | | - | $Qcustomer->bindInt(':customers_id', $osC_Customer->id); |
| |
174 | | - | $Qcustomer->bindInt(':customers_id', $osC_Customer->id); |
| |
| 272 | + | $Qcustomer->bindInt(':customers_id', $osC_Customer->getID()); |
| |
| 273 | + | $Qcustomer->bindInt(':customers_id', $osC_Customer->getID()); |
|
175 | 274 | | $Qcustomer->execute(); |
| |
176 | 275 | | |
| |
177 | 276 | | $Qshipping = $osC_Database->query('select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) left join :table_countries c on (ab.entry_country_id = c.countries_id) where ab.customers_id = :customers_id and ab.address_book_id = :address_book_id'); |
| |
178 | 277 | | $Qshipping->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); |
| |
179 | 278 | | $Qshipping->bindTable(':table_zones', TABLE_ZONES); |
| |
180 | 279 | | $Qshipping->bindTable(':table_countries', TABLE_COUNTRIES); |
  |
181 | | - | $Qshipping->bindInt(':customers_id', $osC_Customer->id); |
| |
182 | | - | $Qshipping->bindInt(':address_book_id', $osC_Session->value('sendto')); |
| |
| 280 | + | $Qshipping->bindInt(':customers_id', $osC_Customer->getID()); |
| |
| 281 | + | $Qshipping->bindInt(':address_book_id', $_SESSION['sendto']); |
|
183 | 282 | | $Qshipping->execute(); |
| |
184 | 283 | | |
| |
185 | 284 | | $Qbilling = $osC_Database->query('select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) left join :table_countries c on (ab.entry_country_id = c.countries_id) where ab.customers_id = :customers_id and ab.address_book_id = :address_book_id'); |
| |
186 | 285 | | $Qbilling->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); |
| |
187 | 286 | | $Qbilling->bindTable(':table_zones', TABLE_ZONES); |
| |
188 | 287 | | $Qbilling->bindTable(':table_countries', TABLE_COUNTRIES); |
  |
189 | | - | $Qbilling->bindInt(':customers_id', $osC_Customer->id); |
| |
190 | | - | $Qbilling->bindInt(':address_book_id', $osC_Session->value('billto')); |
| |
| 288 | + | $Qbilling->bindInt(':customers_id', $osC_Customer->getID()); |
| |
| 289 | + | $Qbilling->bindInt(':address_book_id', $_SESSION['billto']); |
|
191 | 290 | | $Qbilling->execute(); |
| |
192 | 291 | | |
| |
193 | 292 | | $Qtax = $osC_Database->query('select ab.entry_country_id, ab.entry_zone_id from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) where ab.customers_id = :customers_id and ab.address_book_id = :address_book_id'); |
| |
194 | 293 | | $Qtax->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); |
| |
195 | 294 | | $Qtax->bindTable(':table_zones', TABLE_ZONES); |
  |
196 | | - | $Qtax->bindInt(':customers_id', $osC_Customer->id); |
| |
197 | | - | $Qtax->bindInt(':address_book_id', ($this->content_type == 'virtual' ? $osC_Session->value('billto') : $osC_Session->value('sendto'))); |
| |
| 295 | + | $Qtax->bindInt(':customers_id', $osC_Customer->getID()); |
| |
| 296 | + | $Qtax->bindInt(':address_book_id', ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto'])); |
|
198 | 297 | | $Qtax->execute(); |
| |
199 | 298 | | |
| |
200 | 299 | | $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, |
  |
201 | | - | 'currency' => $osC_Session->value('currency'), |
| |
202 | | - | 'currency_value' => $osC_Currencies->currencies[$osC_Session->value('currency')]['value'], |
| |
| 300 | + | 'currency' => $_SESSION['currency'], |
| |
| 301 | + | 'currency_value' => $osC_Currencies->currencies[$_SESSION['currency']]['value'], |
|
203 | 302 | | 'payment_method' => $payment, |
| |
204 | 303 | | 'cc_type' => (isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : ''), |
| |
205 | 304 | | 'cc_owner' => (isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : ''), |
| |
|
|
 |
… |
|
210 | 309 | | 'subtotal' => 0, |
| |
211 | 310 | | 'tax' => 0, |
| |
212 | 311 | | 'tax_groups' => array(), |
  |
213 | | - | 'comments' => ($osC_Session->exists('comments') ? $osC_Session->value('comments') : '')); |
| |
| 312 | + | 'comments' => (isset($_SESSION['comments']) ? $_SESSION['comments'] : '')); |
|
214 | 313 | | |
| |
215 | 314 | | if (isset($GLOBALS[$payment]) && is_object($GLOBALS[$payment])) { |
| |
216 | 315 | | $this->info['payment_method'] = $GLOBALS[$payment]->title; |
| |
|
|
 |
… |
|
261 | 360 | | 'format_id' => $Qbilling->valueInt('address_format_id')); |
| |
262 | 361 | | |
| |
263 | 362 | | $index = 0; |
  |
264 | | - | $products = $cart->get_products(); |
| |
| 363 | + | $products = $_SESSION['cart']->get_products(); |
|
265 | 364 | | for ($i=0, $n=sizeof($products); $i<$n; $i++) { |
| |
266 | 365 | | $this->products[$index] = array('qty' => $products[$i]['quantity'], |
| |
267 | 366 | | 'name' => $products[$i]['name'], |
| |
|
|
 |
… |
|
270 | 369 | | 'tax_description' => $osC_Tax->getTaxRateDescription($products[$i]['tax_class_id'], $Qtax->valueInt('entry_country_id'), $Qtax->valueInt('entry_zone_id')), |
| |
271 | 370 | | 'tax_class_id' => $products[$i]['tax_class_id'], |
| |
272 | 371 | | 'price' => $products[$i]['price'], |
  |
273 | | - | 'final_price' => $products[$i]['price'] + $cart->attributes_price($products[$i]['id']), |
| |
| 372 | + | 'final_price' => $products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id']), |
|
274 | 373 | | 'weight' => $products[$i]['weight'], |
| |
275 | 374 | | 'id' => $products[$i]['id']); |
| |
276 | 375 | | |
| |
|
|
 |
… |
|
285 | 384 | | $Qattributes->bindInt(':products_id', $products[$i]['id']); |
| |
286 | 385 | | $Qattributes->bindInt(':options_id', $option); |
| |
287 | 386 | | $Qattributes->bindInt(':options_values_id', $value); |
  |
288 | | - | $Qattributes->bindInt(':language_id', $osC_Session->value('languages_id')); |
| |
289 | | - | $Qattributes->bindInt(':language_id', $osC_Session->value('languages_id')); |
| |
| 387 | + | $Qattributes->bindInt(':language_id', $_SESSION['languages_id']); |
| |
| 388 | + | $Qattributes->bindInt(':language_id', $_SESSION['languages_id']); |
  |
290 | 389 | | $Qattributes->execute(); |
| |
291 | 390 | | |
| |
292 | 391 | | $this->products[$index]['attributes'][$subindex] = array('option' => $Qattributes->value('products_options_name'), |