Quick Search:

View

Revision:

Diff

Diff from 686 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 686 2006-08-14 22:33:22Z 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'));
hpdl
545
148       $Qorder->bindValue(':billing_country', $osC_ShoppingCart->getBillingAddress('country_title'));
hpdl
521
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'])) {
hpdl
548
199           foreach ($osC_ShoppingCart->getAttributes($products['id']) as $attributes) {
hpdl
521
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
hpdl
538
339       osC_Order::sendEmail($order_id);
340
hpdl
531
341       unset($_SESSION['prepOrderID']);
hpdl
521
342     }
343
hpdl
538
344     function sendEmail($id) {
345       global $osC_Database, $osC_Language, $osC_Currencies;
346
347       $Qorder = $osC_Database->query('select * from :table_orders where orders_id = :orders_id limit 1');
348       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
349       $Qorder->bindInt(':orders_id', $id);
350       $Qorder->execute();
351
352       if ($Qorder->numberOfRows() === 1) {
353         $email_order = STORE_NAME . "\n" .
354                        $osC_Language->get('email_order_separator') . "\n" .
355                        sprintf($osC_Language->get('email_order_order_number'), $id) . "\n" .
hpdl
686
356                        sprintf($osC_Language->get('email_order_invoice_url'), osc_href_link(FILENAME_ACCOUNT, 'orders=' . $id, 'SSL', false, true, true)) . "\n" .
hpdl
548
357                        sprintf($osC_Language->get('email_order_date_ordered'), osC_DateTime::getLong()) . "\n\n" .
358                        $osC_Language->get('email_order_products') . "\n" .
359                        $osC_Language->get('email_order_separator') . "\n";
hpdl
538
360
hpdl
548
361         $Qproducts = $osC_Database->query('select orders_products_id, products_model, products_name, final_price, products_tax, products_quantity from :table_orders_products where orders_id = :orders_id order by orders_products_id');
hpdl
538
362         $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
363         $Qproducts->bindInt(':orders_id', $id);
364         $Qproducts->execute();
365
hpdl
548
366         while ($Qproducts->next()) {
367           $email_order .= $Qproducts->valueInt('products_quantity') . ' x ' . $Qproducts->value('products_name') . ' (' . $Qproducts->value('products_model') . ') = ' . $osC_Currencies->displayPriceWithTaxRate($Qproducts->value('final_price'), $Qproducts->value('products_tax'), $Qproducts->valueInt('products_quantity'), $Qorder->value('currency'), $Qorder->value('currency_value')) . "\n";
hpdl
538
368
hpdl
548
369           $Qattributes = $osC_Database->query('select products_options, products_options_values from :table_orders_products_attributes where orders_id = :orders_id and orders_products_id = :orders_products_id order by orders_products_attributes_id');
370           $Qattributes->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
371           $Qattributes->bindInt(':orders_id', $id);
372           $Qattributes->bindInt(':orders_products_id', $Qproducts->valueInt('orders_products_id'));
373           $Qattributes->execute();
374
375           while ($Qattributes->next()) {
376             $email_order .= "\t" . $Qattributes->value('products_options') . ': ' . $Qattributes->value('products_options_values') . "\n";
377           }
hpdl
538
378         }
379
hpdl
545
380         unset($Qproducts);
hpdl
548
381         unset($Qattributes);
hpdl
545
382
hpdl
548
383         $email_order .= $osC_Language->get('email_order_separator') . "\n";
hpdl
538
384
385         $Qtotals = $osC_Database->query('select title, text from :table_orders_total where orders_id = :orders_id order by sort_order');
386         $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
387         $Qtotals->bindInt(':orders_id', $id);
388         $Qtotals->execute();
389
390         while ($Qtotals->next()) {
391           $email_order .= strip_tags($Qtotals->value('title') . ' ' . $Qtotals->value('text')) . "\n";
392         }
393
hpdl
545
394         unset($Qtotals);
hpdl
538
395
hpdl
545
396         if ( (osc_empty($Qorder->value('delivery_name') === false)) && (osc_empty($Qorder->value('street_address') === false)) ) {
397           $address = array('name' => $Qorder->value('delivery_name'),
398                            'company' => $Qorder->value('delivery_company'),
399                            'street_address' => $Qorder->value('delivery_street_address'),
400                            'suburb' => $Qorder->value('delivery_suburb'),
401                            'city' => $Qorder->value('delivery_city'),
402                            'state' => $Qorder->value('delivery_state'),
403                            'country' => $Qorder->value('delivery_country'),
404                            'postcode' => $Qorder->value('delivery_postcode'));
hpdl
538
405
hpdl
545
406           $email_order .= "\n" . $osC_Language->get('email_order_delivery_address') . "\n" .
407                           $osC_Language->get('email_order_separator') . "\n" .
408                           tep_address_format($Qorder->valueInt('delivery_address_format_id'), $address, false, '', "\n") . "\n";
409
410           unset($address);
411         }
412
413         $address = array('name' => $Qorder->value('billing_name'),
414                          'company' => $Qorder->value('billing_company'),
415                          'street_address' => $Qorder->value('billing_street_address'),
416                          'suburb' => $Qorder->value('billing_suburb'),
417                          'city' => $Qorder->value('billing_city'),
418                          'state' => $Qorder->value('billing_state'),
419                          'country' => $Qorder->value('billing_country'),
420                          'postcode' => $Qorder->value('billing_postcode'));
421
422         $email_order .= "\n" . $osC_Language->get('email_order_billing_address') . "\n" .
423                         $osC_Language->get('email_order_separator') . "\n" .
424                         tep_address_format($Qorder->valueInt('billing_address_format_id'), $address, false, '', "\n") . "\n\n";
425
426         unset($address);
427
428         $Qstatus = $osC_Database->query('select orders_status_name from :table_orders_status where orders_status_id = :orders_status_id and language_id = :language_id');
429         $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
430         $Qstatus->bindInt(':orders_status_id', $Qorder->valueInt('orders_status'));
431         $Qstatus->bindInt(':language_id', $osC_Language->getID());
432         $Qstatus->execute();
433
434         $email_order .= sprintf($osC_Language->get('email_order_status'), $Qstatus->value('orders_status_name')) . "\n" .
435                         $osC_Language->get('email_order_separator') . "\n";
436
437         unset($Qstatus);
438
439         $Qstatuses = $osC_Database->query('select date_added, comments from :table_orders_status_history where orders_id = :orders_id and comments != "" order by orders_status_history_id');
440         $Qstatuses->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
441         $Qstatuses->bindInt(':orders_id', $id);
442         $Qstatuses->execute();
443
444         while ($Qstatuses->next()) {
hpdl
546
445           $email_order .= osC_DateTime::getLong($Qstatuses->value('date_added')) . "\n\t" . wordwrap(str_replace("\n", "\n\t", $Qstatuses->value('comments')), 60, "\n\t", 1) . "\n\n";
hpdl
545
446         }
447
448         unset($Qstatuses);
449
hpdl
538
450 //        if (is_object($GLOBALS[$payment])) {
451 //          $email_order .= $osC_Language->get('email_order_payment_method') . "\n" .
452 //                          $osC_Language->get('email_order_separator') . "\n";
453
454 //          $email_order .= $osC_ShoppingCart->getBillingMethod('title') . "\n\n";
455 //          if (isset($GLOBALS[$payment]->email_footer)) {
456 //            $email_order .= $GLOBALS[$payment]->email_footer . "\n\n";
457 //          }
458 //        }
459
460         tep_mail($Qorder->value('customers_name'), $Qorder->value('customers_email_address'), $osC_Language->get('email_order_subject'), $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
461
462 // send emails to other people
463         if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
464           tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, $osC_Language->get('email_order_subject'), $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
465         }
466       }
hpdl
545
467
468       unset($Qorder);
hpdl
538
469     }
470
hpdl
183
471     function &getListing($limit = null, $page_keyword = 'page') {
hpdl
377
472       global $osC_Database, $osC_Customer, $osC_Language;
hpdl
183
473
hpdl
431
474       $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
475       $Qorders->bindTable(':table_orders', TABLE_ORDERS);
476       $Qorders->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
477       $Qorders->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
hpdl
184
478       $Qorders->bindInt(':customers_id', $osC_Customer->getID());
hpdl
377
479       $Qorders->bindInt(':language_id', $osC_Language->getID());
hpdl
183
480
481       if (is_numeric($limit)) {
482         $Qorders->setBatchLimit(isset($_GET[$page_keyword]) && is_numeric($_GET[$page_keyword]) ? $_GET[$page_keyword] : 1, $limit);
483       }
484
485       $Qorders->execute();
486
487       return $Qorders;
488     }
489
490     function &getStatusListing($id = null) {
hpdl
377
491       global $osC_Database, $osC_Language;
hpdl
183
492
493       if ( ($id === null) && isset($this) ) {
494         $id = $this->_id;
495       }
496
497       $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');
498       $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
499       $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
500       $Qstatus->bindInt(':orders_id', $id);
hpdl
377
501       $Qstatus->bindInt(':language_id', $osC_Language->getID());
hpdl
183
502
503       return $Qstatus;
504     }
505
506     function getCustomerID($id = null) {
507       global $osC_Database;
508
509       if ( ($id === null) && isset($this) ) {
510         $id = $this->_id;
511       }
512
513       $Qcustomer = $osC_Database->query('select customers_id from :table_orders where orders_id = :orders_id');
514       $Qcustomer->bindTable(':table_orders', TABLE_ORDERS);
515       $Qcustomer->bindInt(':orders_id', $id);
516       $Qcustomer->execute();
517
518       return $Qcustomer->valueInt('customers_id');
519     }
520
521     function numberOfEntries() {
522       global $osC_Database, $osC_Customer;
523       static $total_entries;
524
525       if (is_numeric($total_entries) === false) {
526         if ($osC_Customer->isLoggedOn()) {
527           $Qorders = $osC_Database->query('select count(*) as total from :table_orders where customers_id = :customers_id');
528           $Qorders->bindTable(':table_orders', TABLE_ORDERS);
hpdl
184
529           $Qorders->bindInt(':customers_id', $osC_Customer->getID());
hpdl
183
530           $Qorders->execute();
531
532           $total_entries = $Qorders->valueInt('total');
533         } else {
534           $total_entries = 0;
535         }
536       }
537
538       return $total_entries;
539     }
540
541     function numberOfProducts($id = null) {
542       global $osC_Database;
543
544       if ( ($id === null) && isset($this) ) {
545         $id = $this->_id;
546       }
547
548       $Qproducts = $osC_Database->query('select count(*) as total from :table_orders_products where orders_id = :orders_id');
549       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
550       $Qproducts->bindInt(':orders_id', $id);
551       $Qproducts->execute();
552
553       return $Qproducts->valueInt('total');
554     }
555
hpdl
538
556     function exists($id, $customer_id = null) {
557       global $osC_Database;
hpdl
183
558
hpdl
538
559       $Qorder = $osC_Database->query('select orders_id from :table_orders where orders_id = :orders_id');
hpdl
183
560
hpdl
538
561       if (isset($customer_id) && is_numeric($customer_id)) {
562         $Qorder->appendQuery('and customers_id = :customers_id');
563         $Qorder->bindInt(':customers_id', $customer_id);
564       }
565
566       $Qorder->appendQuery('limit 1');
567       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
568       $Qorder->bindInt(':orders_id', $id);
569       $Qorder->execute();
570
571       return ($Qorder->numberOfRows() === 1);
572     }
573
hpdl
1
574     function query($order_id) {
hpdl
377
575       global $osC_Database, $osC_Language;
hpdl
1
576
hpdl
20
577       $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');
578       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
579       $Qorder->bindInt(':orders_id', $order_id);
580       $Qorder->execute();
hpdl
1
581
hpdl
20
582       $Qtotals = $osC_Database->query('select title, text, class from :table_orders_total where orders_id = :orders_id order by sort_order');
583       $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
584       $Qtotals->bindInt(':orders_id', $order_id);
585       $Qtotals->execute();
hpdl
1
586
hpdl
20
587       $shipping_method_string = '';
588       $order_total_string = '';
hpdl
1
589
hpdl
20
590       while ($Qtotals->next()) {
591         $this->totals[] = array('title' => $Qtotals->value('title'),
592                                 'text' => $Qtotals->value('text'));
hpdl
1
593
hpdl
431
594         if ($Qtotals->value('class') == 'shipping') {
hpdl
20
595           $shipping_method_string = strip_tags($Qtotals->value('title'));
hpdl
1
596
hpdl
20
597           if (substr($shipping_method_string, -1) == ':') {
598             $shipping_method_string = substr($Qtotals->value('title'), 0, -1);
599           }
600         }
hpdl
1
601
hpdl
431
602         if ($Qtotals->value('class') == 'total') {
hpdl
20
603           $order_total_string = strip_tags($Qtotals->value('text'));
604         }
605       }
hpdl
1
606
hpdl
20
607       $Qstatus = $osC_Database->query('select orders_status_name from :table_orders_status where orders_status_id = :orders_status_id and language_id = :language_id');
608       $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
hpdl
45
609       $Qstatus->bindInt(':orders_status_id', $Qorder->valueInt('orders_status'));
hpdl
377
610       $Qstatus->bindInt(':language_id', $osC_Language->getID());
hpdl
20
611       $Qstatus->execute();
hpdl
1
612
hpdl
20
613       $this->info = array('currency' => $Qorder->value('currency'),
614                           'currency_value' => $Qorder->value('currency_value'),
615                           'payment_method' => $Qorder->value('payment_method'),
616                           'cc_type' => $Qorder->value('cc_type'),
617                           'cc_owner' => $Qorder->valueProtected('cc_owner'),
618                           'cc_number' => $Qorder->valueProtected('cc_number'),
619                           'cc_expires' => $Qorder->valueProtected('cc_expires'),
620                           'date_purchased' => $Qorder->value('date_purchased'),
621                           'orders_status' => $Qstatus->value('orders_status_name'),
622                           'last_modified' => $Qorder->value('last_modified'),
623                           'total' => $order_total_string,
624                           'shipping_method' => $shipping_method_string);
hpdl
1
625
hpdl
20
626       $this->customer = array('id' => $Qorder->valueInt('customers_id'),
627                               'name' => $Qorder->valueProtected('customers_name'),
628                               'company' => $Qorder->valueProtected('customers_company'),
629                               'street_address' => $Qorder->valueProtected('customers_street_address'),
630                               'suburb' => $Qorder->valueProtected('customers_suburb'),
631                               'city' => $Qorder->valueProtected('customers_city'),
632                               'postcode' => $Qorder->valueProtected('customers_postcode'),
633                               'state' => $Qorder->valueProtected('customers_state'),
634                               'country' => $Qorder->valueProtected('customers_country'),
635                               'format_id' => $Qorder->valueInt('customers_address_format_id'),
636                               'telephone' => $Qorder->valueProtected('customers_telephone'),
637                               'email_address' => $Qorder->valueProtected('customers_email_address'));
638
639       $this->delivery = array('name' => $Qorder->valueProtected('delivery_name'),
640                               'company' => $Qorder->valueProtected('delivery_company'),
641                               'street_address' => $Qorder->valueProtected('delivery_street_address'),
642                               'suburb' => $Qorder->valueProtected('delivery_suburb'),
643                               'city' => $Qorder->valueProtected('delivery_city'),
644                               'postcode' => $Qorder->valueProtected('delivery_postcode'),
645                               'state' => $Qorder->valueProtected('delivery_state'),
646                               'country' => $Qorder->valueProtected('delivery_country'),
647                               'format_id' => $Qorder->valueInt('delivery_address_format_id'));
648
hpdl
1
649       if (empty($this->delivery['name']) && empty($this->delivery['street_address'])) {
650         $this->delivery = false;
651       }
652
hpdl
20
653       $this->billing = array('name' => $Qorder->valueProtected('billing_name'),
654                              'company' => $Qorder->valueProtected('billing_company'),
655                              'street_address' => $Qorder->valueProtected('billing_street_address'),
656                              'suburb' => $Qorder->valueProtected('billing_suburb'),
657                              'city' => $Qorder->valueProtected('billing_city'),
658                              'postcode' => $Qorder->valueProtected('billing_postcode'),
659                              'state' => $Qorder->valueProtected('billing_state'),
660                              'country' => $Qorder->valueProtected('billing_country'),
661                              'format_id' => $Qorder->valueInt('billing_address_format_id'));
hpdl
1
662
hpdl
20
663       $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');
664       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
665       $Qproducts->bindInt(':orders_id', $order_id);
666       $Qproducts->execute();
667
hpdl
1
668       $index = 0;
669
hpdl
20
670       while ($Qproducts->next()) {
hpdl
1
671         $subindex = 0;
672
hpdl
20
673         $this->products[$index] = array('qty' => $Qproducts->valueInt('products_quantity'),
674                                         'id' => $Qproducts->valueInt('products_id'),
675                                         'name' => $Qproducts->value('products_name'),
676                                         'model' => $Qproducts->value('products_model'),
677                                         'tax' => $Qproducts->value('products_tax'),
678                                         'price' => $Qproducts->value('products_price'),
679                                         'final_price' => $Qproducts->value('final_price'));
680
681         $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');
682         $Qattributes->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
683         $Qattributes->bindInt(':orders_id', $order_id);
684         $Qattributes->bindInt(':orders_products_id', $Qproducts->valueInt('orders_products_id'));
685         $Qattributes->execute();
686
687         if ($Qattributes->numberOfRows()) {
688           while ($Qattributes->next()) {
689             $this->products[$index]['attributes'][$subindex] = array('option' => $Qattributes->value('products_options'),
690                                                                      'value' => $Qattributes->value('products_options_values'),
691                                                                      'prefix' => $Qattributes->value('price_prefix'),
692                                                                      'price' => $Qattributes->value('options_values_price'));
693
hpdl
1
694             $subindex++;
695           }
696         }
697
698         $this->info['tax_groups']["{$this->products[$index]['tax']}"] = '1';
699
700         $index++;
701       }
702     }
703   }
704 ?>