Quick Search:

View

Revision:

Diff

Diff from 531 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/order.php

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
20
3   $Id: order.php 531 2006-04-25 15:42:48Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
521
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
hpdl
521
13   class osC_Order {
hpdl
1
14     var $info, $totals, $products, $customer, $delivery, $content_type;
15
hpdl
183
16 /* Private variables */
17
18     var $_id;
19
20 /* Class constructor */
21
hpdl
521
22     function osC_Order($order_id = '') {
hpdl
183
23       if (is_numeric($order_id)) {
24         $this->_id = $order_id;
25       }
26
hpdl
1
27       $this->info = array();
28       $this->totals = array();
29       $this->products = array();
30       $this->customer = array();
31       $this->delivery = array();
32
33       if (tep_not_null($order_id)) {
34         $this->query($order_id);
35       } else {
36         $this->cart();
37       }
38     }
39
hpdl
183
40 /* Public methods */
41
hpdl
521
42     function getStatusID($id) {
43       global $osC_Database;
44
45       $Qorder = $osC_Database->query('select orders_status from :table_orders where orders_id = :orders_id');
46       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
47       $Qorder->bindInt(':orders_id', $id);
48       $Qorder->execute();
49
50       if ($Qorder->numberOfRows()) {
51         return $Qorder->valueInt('orders_status');
52       }
53
54       return false;
55     }
56
57     function remove($id) {
58       global $osC_Database;
59
60       $Qcheck = $osC_Database->query('select orders_status from :table_orders where orders_id = :orders_id');
61       $Qcheck->bindTable(':table_orders', TABLE_ORDERS);
62       $Qcheck->bindInt(':orders_id', $id);
63       $Qcheck->execute();
64
65       if ($Qcheck->valueInt('orders_status') === 4) {
66         $Qdel = $osC_Database->query('delete from :table_orders_products_download where orders_id = :orders_id');
67         $Qdel->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);
68         $Qdel->bindInt(':orders_id', $id);
69         $Qdel->execute();
70
71         $Qdel = $osC_Database->query('delete from :table_orders_products_attributes where orders_id = :orders_id');
72         $Qdel->bindTable(':table_orders_products_aattributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
73         $Qdel->bindInt(':orders_id', $id);
74         $Qdel->execute();
75
76         $Qdel = $osC_Database->query('delete from :table_orders_products where orders_id = :orders_id');
77         $Qdel->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
78         $Qdel->bindInt(':orders_id', $id);
79         $Qdel->execute();
80
81         $Qdel = $osC_Database->query('delete from :table_orders_status_history where orders_id = :orders_id');
82         $Qdel->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
83         $Qdel->bindInt(':orders_id', $id);
84         $Qdel->execute();
85
86         $Qdel = $osC_Database->query('delete from :table_orders_total where orders_id = :orders_id');
87         $Qdel->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
88         $Qdel->bindInt(':orders_id', $id);
89         $Qdel->execute();
90
91         $Qdel = $osC_Database->query('delete from :table_orders where orders_id = :orders_id');
92         $Qdel->bindTable(':table_orders', TABLE_ORDERS);
93         $Qdel->bindInt(':orders_id', $id);
94         $Qdel->execute();
95       }
hpdl
531
96
97       if (isset($_SESSION['prepOrderID'])) {
98         unset($_SESSION['prepOrderID']);
99       }
hpdl
521
100     }
101
102     function insert() {
103       global $osC_Database, $osC_Customer, $osC_Language, $osC_Currencies, $osC_ShoppingCart;
104
hpdl
531
105       if (isset($_SESSION['prepOrderID'])) {
106         $_prep = explode('-', $_SESSION['prepOrderID']);
107
108         if ($_prep[0] == $osC_ShoppingCart->getCartID()) {
109           return $_prep[1]; // order_id
110         } else {
111           if (osC_Order::getStatusID($_prep[1]) === 4) {
112             osC_Order::remove($_prep[1]);
113           }
114         }
115       }
116
hpdl
521
117       $Qorder = $osC_Database->query('insert into :table_orders (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, customers_ip_address, 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, payment_module, cc_type, cc_owner, cc_number, cc_expires, date_purchased, orders_status, currency, currency_value) values (: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, :customers_ip_address, :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, :payment_module, :cc_type, :cc_owner, :cc_number, :cc_expires, now(), :orders_status, :currency, :currency_value)');
118       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
119       $Qorder->bindInt(':customers_id', $osC_Customer->getID());
120       $Qorder->bindValue(':customers_name', $osC_Customer->getName());
121       $Qorder->bindValue(':customers_company', '' /*$order->customer['company']*/);
122       $Qorder->bindValue(':customers_street_address', '' /*$order->customer['street_address']*/);
123       $Qorder->bindValue(':customers_suburb', '' /*$order->customer['suburb']*/);
124       $Qorder->bindValue(':customers_city', '' /*$order->customer['city']*/);
125       $Qorder->bindValue(':customers_postcode', '' /*$order->customer['postcode']*/);
126       $Qorder->bindValue(':customers_state', '' /*$order->customer['state']*/);
127       $Qorder->bindValue(':customers_country', '' /*$order->customer['country']['title']*/);
128       $Qorder->bindValue(':customers_telephone', '' /*$order->customer['telephone']*/);
129       $Qorder->bindValue(':customers_email_address', $osC_Customer->getEmailAddress());
130       $Qorder->bindInt(':customers_address_format_id', $osC_Customer->getDefaultAddressID());
131       $Qorder->bindValue(':customers_ip_address', tep_get_ip_address());
132       $Qorder->bindValue(':delivery_name', $osC_ShoppingCart->getShippingAddress('firstname') . ' ' . $osC_ShoppingCart->getShippingAddress('lastname'));
133       $Qorder->bindValue(':delivery_company', $osC_ShoppingCart->getShippingAddress('company'));
134       $Qorder->bindValue(':delivery_street_address', $osC_ShoppingCart->getShippingAddress('street_address'));
135       $Qorder->bindValue(':delivery_suburb', $osC_ShoppingCart->getShippingAddress('suburb'));
136       $Qorder->bindValue(':delivery_city', $osC_ShoppingCart->getShippingAddress('city'));
137       $Qorder->bindValue(':delivery_postcode', $osC_ShoppingCart->getShippingAddress('postcode'));
138       $Qorder->bindValue(':delivery_state', $osC_ShoppingCart->getShippingAddress('state'));
139       $Qorder->bindValue(':delivery_country', $osC_ShoppingCart->getShippingAddress('country_title'));
140       $Qorder->bindInt(':delivery_address_format_id', $osC_ShoppingCart->getShippingAddress('format_id'));
141       $Qorder->bindValue(':billing_name', $osC_ShoppingCart->getBillingAddress('firstname') . ' ' . $osC_ShoppingCart->getBillingAddress('lastname'));
142       $Qorder->bindValue(':billing_company', $osC_ShoppingCart->getBillingAddress('company'));
143       $Qorder->bindValue(':billing_street_address', $osC_ShoppingCart->getBillingAddress('street_address'));
144       $Qorder->bindValue(':billing_suburb', $osC_ShoppingCart->getBillingAddress('suburb'));
145       $Qorder->bindValue(':billing_city', $osC_ShoppingCart->getBillingAddress('city'));
146       $Qorder->bindValue(':billing_postcode', $osC_ShoppingCart->getBillingAddress('postcode'));
147       $Qorder->bindValue(':billing_state', $osC_ShoppingCart->getBillingAddress('state'));
148       $Qorder->bindValue(':billing_country', $osC_ShoppingCart->getBillingAddress('country_id'));
149       $Qorder->bindInt(':billing_address_format_id', $osC_ShoppingCart->getBillingAddress('format_id'));
150       $Qorder->bindValue(':payment_method', $osC_ShoppingCart->getBillingMethod('title'));
151       $Qorder->bindValue(':payment_module', $GLOBALS['osC_Payment_' . $osC_ShoppingCart->getBillingMethod('id')]->getCode());
152       $Qorder->bindValue(':cc_type', '' /*$order->info['cc_type']*/);
153       $Qorder->bindValue(':cc_owner', '' /*$order->info['cc_owner']*/);
154       $Qorder->bindValue(':cc_number', '' /*$order->info['cc_number']*/);
155       $Qorder->bindValue(':cc_expires', '' /*$order->info['cc_expires']*/);
156       $Qorder->bindInt(':orders_status', 4);
157       $Qorder->bindValue(':currency', $osC_Currencies->getCode());
158       $Qorder->bindValue(':currency_value', $osC_Currencies->value($osC_Currencies->getCode()));
159       $Qorder->execute();
160
161       $insert_id = $osC_Database->nextID();
162
163       foreach ($osC_ShoppingCart->getOrderTotals() as $module) {
164         $Qtotals = $osC_Database->query('insert into :table_orders_total (orders_id, title, text, value, class, sort_order) values (:orders_id, :title, :text, :value, :class, :sort_order)');
165         $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
166         $Qtotals->bindInt(':orders_id', $insert_id);
167         $Qtotals->bindValue(':title', $module['title']);
168         $Qtotals->bindValue(':text', $module['text']);
169         $Qtotals->bindValue(':value', $module['value']);
170         $Qtotals->bindValue(':class', $module['code']);
171         $Qtotals->bindInt(':sort_order', $module['sort_order']);
172         $Qtotals->execute();
173       }
174
175       $Qstatus = $osC_Database->query('insert into :table_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values (:orders_id, :orders_status_id, now(), :customer_notified, :comments)');
176       $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
177       $Qstatus->bindInt(':orders_id', $insert_id);
178       $Qstatus->bindInt(':orders_status_id', 4);
179       $Qstatus->bindInt(':customer_notified', '0');
180       $Qstatus->bindValue(':comments', (isset($_SESSION['comments']) ? $_SESSION['comments'] : ''));
181       $Qstatus->execute();
182
183       foreach ($osC_ShoppingCart->getProducts() as $products) {
184         $Qproducts = $osC_Database->query('insert into :table_orders_products (orders_id, products_id, products_model, products_name, products_price, final_price, products_tax, products_quantity) values (:orders_id, :products_id, :products_model, :products_name, :products_price, :final_price, :products_tax, :products_quantity)');
185         $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
186         $Qproducts->bindInt(':orders_id', $insert_id);
187         $Qproducts->bindInt(':products_id', tep_get_prid($products['id']));
188         $Qproducts->bindValue(':products_model', '' /*$products['model']*/);
189         $Qproducts->bindValue(':products_name', $products['name']);
190         $Qproducts->bindValue(':products_price', $products['price']);
191         $Qproducts->bindValue(':final_price', $products['final_price']);
192         $Qproducts->bindValue(':products_tax', '' /*$products['tax']*/);
193         $Qproducts->bindInt(':products_quantity', $products['quantity']);
194         $Qproducts->execute();
195
196         $order_products_id = $osC_Database->nextID();
197
198         if ($osC_ShoppingCart->hasAttributes($products['id'])) {
199           foreach ($osC_ShoppingCart->getAttributes($products['id']) as $atttributes) {
200             if (DOWNLOAD_ENABLED == '1') {
201               $Qattributes = $osC_Database->query('select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount, pad.products_attributes_filename from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa left join :table_products_attributes_download pad on (pa.products_attributes_id = pad.products_attributes_id) where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :popt_language_id and poval.language_id = :poval_language_id');
202               $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
203               $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
204               $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
205               $Qattributes->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD);
206               $Qattributes->bindInt(':products_id', $products['id']);
207               $Qattributes->bindInt(':options_id', $attributes['options_id']);
208               $Qattributes->bindInt(':options_values_id', $attributes['options_values_id']);
209               $Qattributes->bindInt(':popt_language_id', $osC_Language->getID());
210               $Qattributes->bindInt(':poval_language_id', $osC_Language->getID());
211             } else {
212               $Qattributes = $osC_Database->query('select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :popt_language_id and poval.language_id = :poval_language_id');
213               $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
214               $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
215               $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
216               $Qattributes->bindInt(':products_id', $products['id']);
217               $Qattributes->bindInt(':options_id', $attributes['options_id']);
218               $Qattributes->bindInt(':options_values_id', $attributes['options_values_id']);
219               $Qattributes->bindInt(':popt_language_id', $osC_Language->getID());
220               $Qattributes->bindInt(':poval_language_id', $osC_Language->getID());
221             }
222             $Qattributes->execute();
223
224             $Qopa = $osC_Database->query('insert into :table_orders_products_attributes (orders_id, orders_products_id, products_options, products_options_values, options_values_price, price_prefix) values (:orders_id, :orders_products_id, :products_options, :products_options_values, :options_values_price, :price_prefix)');
225             $Qopa->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
226             $Qopa->bindInt(':orders_id', $insert_id);
227             $Qopa->bindInt(':orders_products_id', $order_products_id);
228             $Qopa->bindValue(':products_options', $Qattributes->value('products_options_name'));
229             $Qopa->bindValue(':products_options_values', $Qattributes->value('products_options_values_name'));
230             $Qopa->bindValue(':options_values_price', $Qattributes->value('options_values_price'));
231             $Qopa->bindValue(':price_prefix', $Qattributes->value('price_prefix'));
232             $Qopa->execute();
233
234             if ((DOWNLOAD_ENABLED == '1') && (strlen($Qattributes->value('products_attributes_filename')) > 0)) {
235               $Qopd = $osC_Database->query('insert into :table_orders_products_download (orders_id, orders_products_id, orders_products_filename, download_maxdays, download_count) values (:orders_id, :orders_products_id, :orders_products_filename, :download_maxdays, :download_count)');
236               $Qopd->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);
237               $Qopd->bindInt(':orders_id', $insert_id);
238               $Qopd->bindInt(':orders_products_id', $order_products_id);
239               $Qopd->bindValue(':orders_products_filename', $Qattributes->value('products_attributes_filename'));
240               $Qopd->bindValue(':download_maxdays', $Qattributes->value('products_attributes_maxdays'));
241               $Qopd->bindValue(':download_count', $Qattributes->value('products_attributes_maxcount'));
242               $Qopd->execute();
243             }
244           }
245         }
246       }
247
hpdl
531
248       $_SESSION['prepOrderID'] = $osC_ShoppingCart->getCartID() . '-' . $insert_id;
249
hpdl
521
250       return $insert_id;
251     }
252
253     function process($order_id, $status_id = '') {
254       global $osC_Database;
255
256       if (empty($status_id) || (is_numeric($status_id) === false)) {
257         $status_id = DEFAULT_ORDERS_STATUS_ID;
258       }
259
260       $Qstatus = $osC_Database->query('insert into :table_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values (:orders_id, :orders_status_id, now(), :customer_notified, :comments)');
261       $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
262       $Qstatus->bindInt(':orders_id', $order_id);
263       $Qstatus->bindInt(':orders_status_id', $status_id);
264       $Qstatus->bindInt(':customer_notified', (SEND_EMAILS == '1') ? '1' : '0');
265       $Qstatus->bindValue(':comments', '');
266       $Qstatus->execute();
267
268       $Qupdate = $osC_Database->query('update :table_orders set orders_status = :orders_status where orders_id = :orders_id');
269       $Qupdate->bindTable(':table_orders', TABLE_ORDERS);
270       $Qupdate->bindInt(':orders_status', $status_id);
271       $Qupdate->bindInt(':orders_id', $order_id);
272       $Qupdate->execute();
273
274       $Qproducts = $osC_Database->query('select products_id, products_quantity from :table_orders_products where orders_id = :orders_id');
275       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
276       $Qproducts->bindInt(':orders_id', $order_id);
277       $Qproducts->execute();
278
279       while ($Qproducts->next()) {
280         if (STOCK_LIMITED == '1') {
281
282 /********** HPDL ; still uses logic from the shopping cart class
283           if (DOWNLOAD_ENABLED == '1') {
284             $Qstock = $osC_Database->query('select products_quantity, pad.products_attributes_filename from :table_products p left join :table_products_attributes pa on (p.products_id = pa.products_id) left join :table_products_attributes_download pad on (pa.products_attributes_id = pad.products_attributes_id) where p.products_id = :products_id');
285             $Qstock->bindTable(':table_products', TABLE_PRODUCTS);
286             $Qstock->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
287             $Qstock->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD);
288             $Qstock->bindInt(':products_id', $Qproducts->valueInt('products_id'));
289
290 // Will work with only one option for downloadable products otherwise, we have to build the query dynamically with a loop
291             if ($osC_ShoppingCart->hasAttributes($products['id'])) {
292               $products_attributes = $osC_ShoppingCart->getAttributes($products['id']);
293               $products_attributes = array_shift($products_attributes);
294
295               $Qstock->appendQuery('and pa.options_id = :options_id and pa.options_values_id = :options_values_id');
296               $Qstock->bindInt(':options_id', $products_attributes['options_id']);
297               $Qstock->bindInt(':options_values_id', $products_attributes['options_values_id']);
298             }
299           } else {
300 ************/
301             $Qstock = $osC_Database->query('select products_quantity from :table_products where products_id = :products_id');
302             $Qstock->bindTable(':table_products', TABLE_PRODUCTS);
303             $Qstock->bindInt(':products_id', $Qproducts->valueInt('products_id'));
304 // HPDL          }
305
306           $Qstock->execute();
307
308           if ($Qstock->numberOfRows() > 0) {
309             $stock_left = $Qstock->valueInt('products_quantity');
310
311 // do not decrement quantities if products_attributes_filename exists
312 // HPDL            if ((DOWNLOAD_ENABLED == '-1') || ((DOWNLOAD_ENABLED == '1') && (strlen($Qstock->value('products_attributes_filename')) < 1))) {
313               $stock_left = $stock_left - $Qproducts->valueInt('products_quantity');
314
315               $Qupdate = $osC_Database->query('update :table_products set products_quantity = :products_quantity where products_id = :products_id');
316               $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
317               $Qupdate->bindInt(':products_quantity', $stock_left);
318               $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id'));
319               $Qupdate->execute();
320 // HPDL            }
321
322             if ((STOCK_ALLOW_CHECKOUT == '-1') && ($stock_left < 1)) {
323               $Qupdate = $osC_Database->query('update :table_products set products_status = 0 where products_id = :products_id');
324               $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
325               $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id'));
326               $Qupdate->execute();
327             }
328           }
329         }
330
331 // Update products_ordered (for bestsellers list)
332         $Qupdate = $osC_Database->query('update :table_products set products_ordered = products_ordered + :products_ordered where products_id = :products_id');
333         $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
334         $Qupdate->bindInt(':products_ordered', $Qproducts->valueInt('products_quantity'));
335         $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id'));
336         $Qupdate->execute();
337       }
hpdl
531
338
339       unset($_SESSION['prepOrderID']);
hpdl
521
340     }
341
hpdl
183
342     function &getListing($limit = null, $page_keyword = 'page') {
hpdl
377
343       global $osC_Database, $osC_Customer, $osC_Language;
hpdl
183
344
hpdl
431
345       $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 = "total" and o.orders_status = s.orders_status_id and s.language_id = :language_id order by orders_id desc');
hpdl
183
346       $Qorders->bindTable(':table_orders', TABLE_ORDERS);
347       $Qorders->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
348       $Qorders->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
hpdl
184
349       $Qorders->bindInt(':customers_id', $osC_Customer->getID());
hpdl
377
350       $Qorders->bindInt(':language_id', $osC_Language->getID());
hpdl
183
351
352       if (is_numeric($limit)) {
353         $Qorders->setBatchLimit(isset($_GET[$page_keyword]) && is_numeric($_GET[$page_keyword]) ? $_GET[$page_keyword] : 1, $limit);
354       }
355
356       $Qorders->execute();
357
358       return $Qorders;
359     }
360
361     function &getStatusListing($id = null) {
hpdl
377
362       global $osC_Database, $osC_Language;
hpdl
183
363
364       if ( ($id === null) && isset($this) ) {
365         $id = $this->_id;
366       }
367
368       $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');
369       $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
370       $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
371       $Qstatus->bindInt(':orders_id', $id);
hpdl
377
372       $Qstatus->bindInt(':language_id', $osC_Language->getID());
hpdl
183
373
374       return $Qstatus;
375     }
376
377     function getCustomerID($id = null) {
378       global $osC_Database;
379
380       if ( ($id === null) && isset($this) ) {
381         $id = $this->_id;
382       }
383
384       $Qcustomer = $osC_Database->query('select customers_id from :table_orders where orders_id = :orders_id');
385       $Qcustomer->bindTable(':table_orders', TABLE_ORDERS);
386       $Qcustomer->bindInt(':orders_id', $id);
387       $Qcustomer->execute();
388
389       return $Qcustomer->valueInt('customers_id');
390     }
391
392     function numberOfEntries() {
393       global $osC_Database, $osC_Customer;
394       static $total_entries;
395
396       if (is_numeric($total_entries) === false) {
397         if ($osC_Customer->isLoggedOn()) {
398           $Qorders = $osC_Database->query('select count(*) as total from :table_orders where customers_id = :customers_id');
399           $Qorders->bindTable(':table_orders', TABLE_ORDERS);
hpdl
184
400           $Qorders->bindInt(':customers_id', $osC_Customer->getID());
hpdl
183
401           $Qorders->execute();
402
403           $total_entries = $Qorders->valueInt('total');
404         } else {
405           $total_entries = 0;
406         }
407       }
408
409       return $total_entries;
410     }
411
412     function numberOfProducts($id = null) {
413       global $osC_Database;
414
415       if ( ($id === null) && isset($this) ) {
416         $id = $this->_id;
417       }
418
419       $Qproducts = $osC_Database->query('select count(*) as total from :table_orders_products where orders_id = :orders_id');
420       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
421       $Qproducts->bindInt(':orders_id', $id);
422       $Qproducts->execute();
423
424       return $Qproducts->valueInt('total');
425     }
426
427
428
hpdl
1
429     function query($order_id) {
hpdl
377
430       global $osC_Database, $osC_Language;
hpdl
1
431
hpdl
20
432       $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');
433       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
434       $Qorder->bindInt(':orders_id', $order_id);
435       $Qorder->execute();
hpdl
1
436
hpdl
20
437       $Qtotals = $osC_Database->query('select title, text, class from :table_orders_total where orders_id = :orders_id order by sort_order');
438       $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
439       $Qtotals->bindInt(':orders_id', $order_id);
440       $Qtotals->execute();
hpdl
1
441
hpdl
20
442       $shipping_method_string = '';
443       $order_total_string = '';
hpdl
1
444
hpdl
20
445       while ($Qtotals->next()) {
446         $this->totals[] = array('title' => $Qtotals->value('title'),
447                                 'text' => $Qtotals->value('text'));
hpdl
1
448
hpdl
431
449         if ($Qtotals->value('class') == 'shipping') {
hpdl
20
450           $shipping_method_string = strip_tags($Qtotals->value('title'));
hpdl
1
451
hpdl
20
452           if (substr($shipping_method_string, -1) == ':') {
453             $shipping_method_string = substr($Qtotals->value('title'), 0, -1);
454           }
455         }
hpdl
1
456
hpdl
431
457         if ($Qtotals->value('class') == 'total') {
hpdl
20
458           $order_total_string = strip_tags($Qtotals->value('text'));
459         }
460       }
hpdl
1
461
hpdl
20
462       $Qstatus = $osC_Database->query('select orders_status_name from :table_orders_status where orders_status_id = :orders_status_id and language_id = :language_id');
463       $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
hpdl
45
464       $Qstatus->bindInt(':orders_status_id', $Qorder->valueInt('orders_status'));
hpdl
377
465       $Qstatus->bindInt(':language_id', $osC_Language->getID());
hpdl
20
466       $Qstatus->execute();
hpdl
1
467
hpdl
20
468       $this->info = array('currency' => $Qorder->value('currency'),
469                           'currency_value' => $Qorder->value('currency_value'),
470                           'payment_method' => $Qorder->value('payment_method'),
471                           'cc_type' => $Qorder->value('cc_type'),
472                           'cc_owner' => $Qorder->valueProtected('cc_owner'),
473                           'cc_number' => $Qorder->valueProtected('cc_number'),
474                           'cc_expires' => $Qorder->valueProtected('cc_expires'),
475                           'date_purchased' => $Qorder->value('date_purchased'),
476                           'orders_status' => $Qstatus->value('orders_status_name'),
477                           'last_modified' => $Qorder->value('last_modified'),
478                           'total' => $order_total_string,
479                           'shipping_method' => $shipping_method_string);
hpdl
1
480
hpdl
20
481       $this->customer = array('id' => $Qorder->valueInt('customers_id'),
482                               'name' => $Qorder->valueProtected('customers_name'),
483                               'company' => $Qorder->valueProtected('customers_company'),
484                               'street_address' => $Qorder->valueProtected('customers_street_address'),
485                               'suburb' => $Qorder->valueProtected('customers_suburb'),
486                               'city' => $Qorder->valueProtected('customers_city'),
487                               'postcode' => $Qorder->valueProtected('customers_postcode'),
488                               'state' => $Qorder->valueProtected('customers_state'),
489                               'country' => $Qorder->valueProtected('customers_country'),
490                               'format_id' => $Qorder->valueInt('customers_address_format_id'),
491                               'telephone' => $Qorder->valueProtected('customers_telephone'),
492                               'email_address' => $Qorder->valueProtected('customers_email_address'));
493
494       $this->delivery = array('name' => $Qorder->valueProtected('delivery_name'),
495                               'company' => $Qorder->valueProtected('delivery_company'),
496                               'street_address' => $Qorder->valueProtected('delivery_street_address'),
497                               'suburb' => $Qorder->valueProtected('delivery_suburb'),
498                               'city' => $Qorder->valueProtected('delivery_city'),
499                               'postcode' => $Qorder->valueProtected('delivery_postcode'),
500                               'state' => $Qorder->valueProtected('delivery_state'),
501                               'country' => $Qorder->valueProtected('delivery_country'),
502                               'format_id' => $Qorder->valueInt('delivery_address_format_id'));
503
hpdl
1
504       if (empty($this->delivery['name']) && empty($this->delivery['street_address'])) {
505         $this->delivery = false;
506       }
507
hpdl
20
508       $this->billing = array('name' => $Qorder->valueProtected('billing_name'),
509                              'company' => $Qorder->valueProtected('billing_company'),
510                              'street_address' => $Qorder->valueProtected('billing_street_address'),
511                              'suburb' => $Qorder->valueProtected('billing_suburb'),
512                              'city' => $Qorder->valueProtected('billing_city'),
513                              'postcode' => $Qorder->valueProtected('billing_postcode'),
514                              'state' => $Qorder->valueProtected('billing_state'),
515                              'country' => $Qorder->valueProtected('billing_country'),
516                              'format_id' => $Qorder->valueInt('billing_address_format_id'));
hpdl
1
517
hpdl
20
518       $Qproducts = $osC_Database->query('select orders_products_id, products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from :table_orders_products where orders_id = :orders_id');
519       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
520       $Qproducts->bindInt(':orders_id', $order_id);
521       $Qproducts->execute();
522
hpdl
1
523       $index = 0;
524
hpdl
20
525       while ($Qproducts->next()) {
hpdl
1
526         $subindex = 0;
527
hpdl
20
528         $this->products[$index] = array('qty' => $Qproducts->valueInt('products_quantity'),
529                                         'id' => $Qproducts->valueInt('products_id'),
530                                         'name' => $Qproducts->value('products_name'),
531                                         'model' => $Qproducts->value('products_model'),
532                                         'tax' => $Qproducts->value('products_tax'),
533                                         'price' => $Qproducts->value('products_price'),
534                                         'final_price' => $Qproducts->value('final_price'));
535
536         $Qattributes = $osC_Database->query('select products_options, products_options_values, options_values_price, price_prefix from :table_orders_products_attributes where orders_id = :orders_id and orders_products_id = :orders_products_id');
537         $Qattributes->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
538         $Qattributes->bindInt(':orders_id', $order_id);
539         $Qattributes->bindInt(':orders_products_id', $Qproducts->valueInt('orders_products_id'));
540         $Qattributes->execute();
541
542         if ($Qattributes->numberOfRows()) {
543           while ($Qattributes->next()) {
544             $this->products[$index]['attributes'][$subindex] = array('option' => $Qattributes->value('products_options'),
545                                                                      'value' => $Qattributes->value('products_options_values'),
546                                                                      'prefix' => $Qattributes->value('price_prefix'),
547                                                                      'price' => $Qattributes->value('options_values_price'));
548
hpdl
1
549             $subindex++;
550           }
551         }
552
553         $this->info['tax_groups']["{$this->products[$index]['tax']}"] = '1';
554
555         $index++;
556       }
557     }
558   }
559 ?>