Quick Search:

View

Revision:

Diff

Diff from 20 to:

Annotations

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

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
20
3   $Id: order.php 20 2005-02-25 18:34:41Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
20
8   Copyright (c) 2005 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
13   class order {
14     var $info, $totals, $products, $customer, $delivery, $content_type;
15
16     function order($order_id = '') {
17       $this->info = array();
18       $this->totals = array();
19       $this->products = array();
20       $this->customer = array();
21       $this->delivery = array();
22
23       if (tep_not_null($order_id)) {
24         $this->query($order_id);
25       } else {
26         $this->cart();
27       }
28     }
29
30     function query($order_id) {
hpdl
20
31       global $osC_Database, $osC_Session;
hpdl
1
32
hpdl
20
33       $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       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
35       $Qorder->bindInt(':orders_id', $order_id);
36       $Qorder->execute();
hpdl
1
37
hpdl
20
38       $Qtotals = $osC_Database->query('select title, text, class from :table_orders_total where orders_id = :orders_id order by sort_order');
39       $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
40       $Qtotals->bindInt(':orders_id', $order_id);
41       $Qtotals->execute();
hpdl
1
42
hpdl
20
43       $shipping_method_string = '';
44       $order_total_string = '';
hpdl
1
45
hpdl
20
46       while ($Qtotals->next()) {
47         $this->totals[] = array('title' => $Qtotals->value('title'),
48                                 'text' => $Qtotals->value('text'));
hpdl
1
49
hpdl
20
50         if ($Qtotals->value('class') == 'ot_shipping') {
51           $shipping_method_string = strip_tags($Qtotals->value('title'));
hpdl
1
52
hpdl
20
53           if (substr($shipping_method_string, -1) == ':') {
54             $shipping_method_string = substr($Qtotals->value('title'), 0, -1);
55           }
56         }
hpdl
1
57
hpdl
20
58         if ($Qtotals->value('class') == 'ot_total') {
59           $order_total_string = strip_tags($Qtotals->value('text'));
60         }
61       }
hpdl
1
62
hpdl
20
63       $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       $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
65       $Qstatus->bindInt(':orders_status', $Qorder->valueInt('orders_status'));
66       $Qstatus->bindInt(':language_id', $osC_Session->value('languages_id'));
67       $Qstatus->execute();
hpdl
1
68
hpdl
20
69       $this->info = array('currency' => $Qorder->value('currency'),
70                           'currency_value' => $Qorder->value('currency_value'),
71                           'payment_method' => $Qorder->value('payment_method'),
72                           'cc_type' => $Qorder->value('cc_type'),
73                           'cc_owner' => $Qorder->valueProtected('cc_owner'),
74                           'cc_number' => $Qorder->valueProtected('cc_number'),
75                           'cc_expires' => $Qorder->valueProtected('cc_expires'),
76                           'date_purchased' => $Qorder->value('date_purchased'),
77                           'orders_status' => $Qstatus->value('orders_status_name'),
78                           'last_modified' => $Qorder->value('last_modified'),
79                           'total' => $order_total_string,
80                           'shipping_method' => $shipping_method_string);
hpdl
1
81
hpdl
20
82       $this->customer = array('id' => $Qorder->valueInt('customers_id'),
83                               'name' => $Qorder->valueProtected('customers_name'),
84                               'company' => $Qorder->valueProtected('customers_company'),
85                               'street_address' => $Qorder->valueProtected('customers_street_address'),
86                               'suburb' => $Qorder->valueProtected('customers_suburb'),
87                               'city' => $Qorder->valueProtected('customers_city'),
88                               'postcode' => $Qorder->valueProtected('customers_postcode'),
89                               'state' => $Qorder->valueProtected('customers_state'),
90                               'country' => $Qorder->valueProtected('customers_country'),
91                               'format_id' => $Qorder->valueInt('customers_address_format_id'),
92                               'telephone' => $Qorder->valueProtected('customers_telephone'),
93                               'email_address' => $Qorder->valueProtected('customers_email_address'));
94
95       $this->delivery = array('name' => $Qorder->valueProtected('delivery_name'),
96                               'company' => $Qorder->valueProtected('delivery_company'),
97                               'street_address' => $Qorder->valueProtected('delivery_street_address'),
98                               'suburb' => $Qorder->valueProtected('delivery_suburb'),
99                               'city' => $Qorder->valueProtected('delivery_city'),
100                               'postcode' => $Qorder->valueProtected('delivery_postcode'),
101                               'state' => $Qorder->valueProtected('delivery_state'),
102                               'country' => $Qorder->valueProtected('delivery_country'),
103                               'format_id' => $Qorder->valueInt('delivery_address_format_id'));
104
hpdl
1
105       if (empty($this->delivery['name']) && empty($this->delivery['street_address'])) {
106         $this->delivery = false;
107       }
108
hpdl
20
109       $this->billing = array('name' => $Qorder->valueProtected('billing_name'),
110                              'company' => $Qorder->valueProtected('billing_company'),
111                              'street_address' => $Qorder->valueProtected('billing_street_address'),
112                              'suburb' => $Qorder->valueProtected('billing_suburb'),
113                              'city' => $Qorder->valueProtected('billing_city'),
114                              'postcode' => $Qorder->valueProtected('billing_postcode'),
115                              'state' => $Qorder->valueProtected('billing_state'),
116                              'country' => $Qorder->valueProtected('billing_country'),
117                              'format_id' => $Qorder->valueInt('billing_address_format_id'));
hpdl
1
118
hpdl
20
119       $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');
120       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
121       $Qproducts->bindInt(':orders_id', $order_id);
122       $Qproducts->execute();
123
hpdl
1
124       $index = 0;
125
hpdl
20
126       while ($Qproducts->next()) {
hpdl
1
127         $subindex = 0;
128
hpdl
20
129         $this->products[$index] = array('qty' => $Qproducts->valueInt('products_quantity'),
130                                         'id' => $Qproducts->valueInt('products_id'),
131                                         'name' => $Qproducts->value('products_name'),
132                                         'model' => $Qproducts->value('products_model'),
133                                         'tax' => $Qproducts->value('products_tax'),
134                                         'price' => $Qproducts->value('products_price'),
135                                         'final_price' => $Qproducts->value('final_price'));
136
137         $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');
138         $Qattributes->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
139         $Qattributes->bindInt(':orders_id', $order_id);
140         $Qattributes->bindInt(':orders_products_id', $Qproducts->valueInt('orders_products_id'));
141         $Qattributes->execute();
142
143         if ($Qattributes->numberOfRows()) {
144           while ($Qattributes->next()) {
145             $this->products[$index]['attributes'][$subindex] = array('option' => $Qattributes->value('products_options'),
146                                                                      'value' => $Qattributes->value('products_options_values'),
147                                                                      'prefix' => $Qattributes->value('price_prefix'),
148                                                                      'price' => $Qattributes->value('options_values_price'));
149
hpdl
1
150             $subindex++;
151           }
152         }
153
154         $this->info['tax_groups']["{$this->products[$index]['tax']}"] = '1';
155
156         $index++;
157       }
158     }
159
160     function cart() {
hpdl
20
161       global $osC_Database, $osC_Session, $osC_Customer, $osC_Tax, $cart, $osC_Currencies;
hpdl
1
162
163       $this->content_type = $cart->get_content_type();
164
165       $shipping =& $osC_Session->value('shipping');
166       $payment =& $osC_Session->value('payment');
167
hpdl
20
168       $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       $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
170       $Qcustomer->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
171       $Qcustomer->bindTable(':table_zones', TABLE_ZONES);
172       $Qcustomer->bindTable(':table_countries', TABLE_COUNTRIES);
173       $Qcustomer->bindInt(':customers_id', $osC_Customer->id);
174       $Qcustomer->bindInt(':customers_id', $osC_Customer->id);
175       $Qcustomer->execute();
hpdl
1
176
hpdl
20
177       $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       $Qshipping->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
179       $Qshipping->bindTable(':table_zones', TABLE_ZONES);
180       $Qshipping->bindTable(':table_countries', TABLE_COUNTRIES);
181       $Qshipping->bindInt(':customers_id', $osC_Customer->id);
182       $Qshipping->bindInt(':address_book_id', $osC_Session->value('sendto'));
183       $Qshipping->execute();
hpdl
1
184
hpdl
20
185       $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       $Qbilling->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
187       $Qbilling->bindTable(':table_zones', TABLE_ZONES);
188       $Qbilling->bindTable(':table_countries', TABLE_COUNTRIES);
189       $Qbilling->bindInt(':customers_id', $osC_Customer->id);
190       $Qbilling->bindInt(':address_book_id', $osC_Session->value('billto'));
191       $Qbilling->execute();
hpdl
1
192
hpdl
20
193       $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       $Qtax->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
195       $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')));
198       $Qtax->execute();
hpdl
1
199
200       $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'],
203                           'payment_method' => $payment,
204                           'cc_type' => (isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : ''),
205                           'cc_owner' => (isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : ''),
206                           'cc_number' => (isset($GLOBALS['cc_number']) ? $GLOBALS['cc_number'] : ''),
207                           'cc_expires' => (isset($GLOBALS['cc_expires']) ? $GLOBALS['cc_expires'] : ''),
208                           'shipping_method' => $shipping['title'],
209                           'shipping_cost' => $shipping['cost'],
210                           'subtotal' => 0,
211                           'tax' => 0,
212                           'tax_groups' => array(),
213                           'comments' => ($osC_Session->exists('comments') ? $osC_Session->value('comments') : ''));
214
215       if (isset($GLOBALS[$payment]) && is_object($GLOBALS[$payment])) {
216         $this->info['payment_method'] = $GLOBALS[$payment]->title;
217
218         if ( isset($GLOBALS[$payment]->order_status) && is_numeric($GLOBALS[$payment]->order_status) && ($GLOBALS[$payment]->order_status > 0) ) {
219           $this->info['order_status'] = $GLOBALS[$payment]->order_status;
220         }
221       }
222
hpdl
20
223       $this->customer = array('firstname' => $Qcustomer->valueProtected('customers_firstname'),
224                               'lastname' => $Qcustomer->valueProtected('customers_lastname'),
225                               'company' => $Qcustomer->valueProtected('entry_company'),
226                               'street_address' => $Qcustomer->valueProtected('entry_street_address'),
227                               'suburb' => $Qcustomer->valueProtected('entry_suburb'),
228                               'city' => $Qcustomer->valueProtected('entry_city'),
229                               'postcode' => $Qcustomer->valueProtected('entry_postcode'),
230                               'state' => (tep_not_null($Qcustomer->valueProtected('entry_state')) ? $Qcustomer->valueProtected('entry_state') : $Qcustomer->valueProtected('zone_name')),
231                               'zone_id' => $Qcustomer->valueInt('entry_zone_id'),
232                               'country' => array('id' => $Qcustomer->valueInt('countries_id'), 'title' => $Qcustomer->value('countries_name'), 'iso_code_2' => $Qcustomer->value('countries_iso_code_2'), 'iso_code_3' => $Qcustomer->value('countries_iso_code_3')),
233                               'format_id' => $Qcustomer->valueInt('address_format_id'),
234                               'telephone' => $Qcustomer->valueProtected('customers_telephone'),
235                               'email_address' => $Qcustomer->valueProtected('customers_email_address'));
hpdl
1
236
hpdl
20
237       $this->delivery = array('firstname' => $Qshipping->valueProtected('entry_firstname'),
238                               'lastname' => $Qshipping->valueProtected('entry_lastname'),
239                               'company' => $Qshipping->valueProtected('entry_company'),
240                               'street_address' => $Qshipping->valueProtected('entry_street_address'),
241                               'suburb' => $Qshipping->valueProtected('entry_suburb'),
242                               'city' => $Qshipping->valueProtected('entry_city'),
243                               'postcode' => $Qshipping->valueProtected('entry_postcode'),
244                               'state' => (tep_not_null($Qshipping->valueProtected('entry_state')) ? $Qshipping->valueProtected('entry_state') : $Qshipping->valueProtected('zone_name')),
245                               'zone_id' => $Qshipping->valueInt('entry_zone_id'),
246                               'country' => array('id' => $Qshipping->valueInt('countries_id'), 'title' => $Qshipping->value('countries_name'), 'iso_code_2' => $Qshipping->value('countries_iso_code_2'), 'iso_code_3' => $Qshipping->value('countries_iso_code_3')),
247                               'country_id' => $Qshipping->valueInt('entry_country_id'),
248                               'format_id' => $Qshipping->valueInt('address_format_id'));
hpdl
1
249
hpdl
20
250       $this->billing = array('firstname' => $Qbilling->valueProtected('entry_firstname'),
251                              'lastname' => $Qbilling->valueProtected('entry_lastname'),
252                              'company' => $Qbilling->valueProtected('entry_company'),
253                              'street_address' => $Qbilling->valueProtected('entry_street_address'),
254                              'suburb' => $Qbilling->valueProtected('entry_suburb'),
255                              'city' => $Qbilling->valueProtected('entry_city'),
256                              'postcode' => $Qbilling->valueProtected('entry_postcode'),
257                              'state' => (tep_not_null($Qbilling->valueProtected('entry_state')) ? $Qbilling->valueProtected('entry_state') : $Qbilling->valueProtected('zone_name')),
258                              'zone_id' => $Qbilling->valueInt('entry_zone_id'),
259                              'country' => array('id' => $Qbilling->valueInt('countries_id'), 'title' => $Qbilling->value('countries_name'), 'iso_code_2' => $Qbilling->value('countries_iso_code_2'), 'iso_code_3' => $Qbilling->value('countries_iso_code_3')),
260                              'country_id' => $Qbilling->valueInt('entry_country_id'),
261                              'format_id' => $Qbilling->valueInt('address_format_id'));
hpdl
1
262
263       $index = 0;
264       $products = $cart->get_products();
265       for ($i=0, $n=sizeof($products); $i<$n; $i++) {
266         $this->products[$index] = array('qty' => $products[$i]['quantity'],
267                                         'name' => $products[$i]['name'],
268                                         'model' => $products[$i]['model'],
hpdl
20
269                                         'tax' => $osC_Tax->getTaxRate($products[$i]['tax_class_id'], $Qtax->valueInt('entry_country_id'), $Qtax->valueInt('entry_zone_id')),
270                                         'tax_description' => $osC_Tax->getTaxRateDescription($products[$i]['tax_class_id'], $Qtax->valueInt('entry_country_id'), $Qtax->valueInt('entry_zone_id')),
hpdl
1
271                                         'tax_class_id' => $products[$i]['tax_class_id'],
272                                         'price' => $products[$i]['price'],
273                                         'final_price' => $products[$i]['price'] + $cart->attributes_price($products[$i]['id']),
274                                         'weight' => $products[$i]['weight'],
275                                         'id' => $products[$i]['id']);
276
277         if ($products[$i]['attributes']) {
278           $subindex = 0;
279           reset($products[$i]['attributes']);
280           while (list($option, $value) = each($products[$i]['attributes'])) {
hpdl
20
281             $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 = :language_id and poval.language_id = :language_id');
282             $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
283             $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
284             $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
285             $Qattributes->bindInt(':products_id', $products[$i]['id']);
286             $Qattributes->bindInt(':options_id', $option);
287             $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'));
290             $Qattributes->execute();
hpdl
1
291
hpdl
20
292             $this->products[$index]['attributes'][$subindex] = array('option' => $Qattributes->value('products_options_name'),
293                                                                      'value' => $Qattributes->value('products_options_values_name'),
hpdl
1
294                                                                      'option_id' => $option,
295                                                                      'value_id' => $value,
hpdl
20
296                                                                      'prefix' => $Qattributes->value('price_prefix'),
297                                                                      'price' => $Qattributes->value('options_values_price'));
hpdl
1
298
299             $subindex++;
300           }
301         }
302
303         $shown_price = tep_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'];
304         $this->info['subtotal'] += $shown_price;
305
306         $products_tax = $this->products[$index]['tax'];
307         $products_tax_description = $this->products[$index]['tax_description'];
308         if (DISPLAY_PRICE_WITH_TAX == 'true') {
309           $this->info['tax'] += $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)));
310           if (isset($this->info['tax_groups']["$products_tax_description"])) {
311             $this->info['tax_groups']["$products_tax_description"] += $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)));
312           } else {
313             $this->info['tax_groups']["$products_tax_description"] = $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)));
314           }
315         } else {
316           $this->info['tax'] += ($products_tax / 100) * $shown_price;
317           if (isset($this->info['tax_groups']["$products_tax_description"])) {
318             $this->info['tax_groups']["$products_tax_description"] += ($products_tax / 100) * $shown_price;
319           } else {
320             $this->info['tax_groups']["$products_tax_description"] = ($products_tax / 100) * $shown_price;
321           }
322         }
323
324         $index++;
325       }
326
327       if (DISPLAY_PRICE_WITH_TAX == 'true') {
328         $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
329       } else {
330         $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
331       }
332     }
333   }
334 ?>