hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
|
3
|
$Id: order.php,v 1.36 2003/12/18 23:27:01 hpdl Exp $
|
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
|
8
|
Copyright (c) 2003 osCommerce
|
|
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) {
|
|
31
|
global $osC_Session;
|
|
32
|
|
|
33
|
$order_id = tep_db_prepare_input($order_id);
|
|
34
|
|
|
35
|
$order_query = tep_db_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 = '" . (int)$order_id . "'");
|
|
36
|
$order = tep_db_fetch_array($order_query);
|
|
37
|
|
|
38
|
$totals_query = tep_db_query("select title, text from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' order by sort_order");
|
|
39
|
while ($totals = tep_db_fetch_array($totals_query)) {
|
|
40
|
$this->totals[] = array('title' => $totals['title'],
|
|
41
|
'text' => $totals['text']);
|
|
42
|
}
|
|
43
|
|
|
44
|
$order_total_query = tep_db_query("select text from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' and class = 'ot_total'");
|
|
45
|
$order_total = tep_db_fetch_array($order_total_query);
|
|
46
|
|
|
47
|
$shipping_method_query = tep_db_query("select title from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' and class = 'ot_shipping'");
|
|
48
|
$shipping_method = tep_db_fetch_array($shipping_method_query);
|
|
49
|
|
|
50
|
$order_status_query = tep_db_query("select orders_status_name from " . TABLE_ORDERS_STATUS . " where orders_status_id = '" . $order['orders_status'] . "' and language_id = '" . (int)$osC_Session->value('languages_id') . "'");
|
|
51
|
$order_status = tep_db_fetch_array($order_status_query);
|
|
52
|
|
|
53
|
$this->info = array('currency' => $order['currency'],
|
|
54
|
'currency_value' => $order['currency_value'],
|
|
55
|
'payment_method' => $order['payment_method'],
|
|
56
|
'cc_type' => $order['cc_type'],
|
|
57
|
'cc_owner' => $order['cc_owner'],
|
|
58
|
'cc_number' => $order['cc_number'],
|
|
59
|
'cc_expires' => $order['cc_expires'],
|
|
60
|
'date_purchased' => $order['date_purchased'],
|
|
61
|
'orders_status' => $order_status['orders_status_name'],
|
|
62
|
'last_modified' => $order['last_modified'],
|
|
63
|
'total' => strip_tags($order_total['text']),
|
|
64
|
'shipping_method' => ((substr($shipping_method['title'], -1) == ':') ? substr(strip_tags($shipping_method['title']), 0, -1) : strip_tags($shipping_method['title'])));
|
|
65
|
|
|
66
|
$this->customer = array('id' => $order['customers_id'],
|
|
67
|
'name' => $order['customers_name'],
|
|
68
|
'company' => $order['customers_company'],
|
|
69
|
'street_address' => $order['customers_street_address'],
|
|
70
|
'suburb' => $order['customers_suburb'],
|
|
71
|
'city' => $order['customers_city'],
|
|
72
|
'postcode' => $order['customers_postcode'],
|
|
73
|
'state' => $order['customers_state'],
|
|
74
|
'country' => $order['customers_country'],
|
|
75
|
'format_id' => $order['customers_address_format_id'],
|
|
76
|
'telephone' => $order['customers_telephone'],
|
|
77
|
'email_address' => $order['customers_email_address']);
|
|
78
|
|
|
79
|
$this->delivery = array('name' => $order['delivery_name'],
|
|
80
|
'company' => $order['delivery_company'],
|
|
81
|
'street_address' => $order['delivery_street_address'],
|
|
82
|
'suburb' => $order['delivery_suburb'],
|
|
83
|
'city' => $order['delivery_city'],
|
|
84
|
'postcode' => $order['delivery_postcode'],
|
|
85
|
'state' => $order['delivery_state'],
|
|
86
|
'country' => $order['delivery_country'],
|
|
87
|
'format_id' => $order['delivery_address_format_id']);
|
|
88
|
|
|
89
|
if (empty($this->delivery['name']) && empty($this->delivery['street_address'])) {
|
|
90
|
$this->delivery = false;
|
|
91
|
}
|
|
92
|
|
|
93
|
$this->billing = array('name' => $order['billing_name'],
|
|
94
|
'company' => $order['billing_company'],
|
|
95
|
'street_address' => $order['billing_street_address'],
|
|
96
|
'suburb' => $order['billing_suburb'],
|
|
97
|
'city' => $order['billing_city'],
|
|
98
|
'postcode' => $order['billing_postcode'],
|
|
99
|
'state' => $order['billing_state'],
|
|
100
|
'country' => $order['billing_country'],
|
|
101
|
'format_id' => $order['billing_address_format_id']);
|
|
102
|
|
|
103
|
$index = 0;
|
|
104
|
$orders_products_query = tep_db_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 = '" . (int)$order_id . "'");
|
|
105
|
while ($orders_products = tep_db_fetch_array($orders_products_query)) {
|
|
106
|
$this->products[$index] = array('qty' => $orders_products['products_quantity'],
|
|
107
|
'id' => $orders_products['products_id'],
|
|
108
|
'name' => $orders_products['products_name'],
|
|
109
|
'model' => $orders_products['products_model'],
|
|
110
|
'tax' => $orders_products['products_tax'],
|
|
111
|
'price' => $orders_products['products_price'],
|
|
112
|
'final_price' => $orders_products['final_price']);
|
|
113
|
|
|
114
|
$subindex = 0;
|
|
115
|
$attributes_query = tep_db_query("select products_options, products_options_values, options_values_price, price_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order_id . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'");
|
|
116
|
if (tep_db_num_rows($attributes_query)) {
|
|
117
|
while ($attributes = tep_db_fetch_array($attributes_query)) {
|
|
118
|
$this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'],
|
|
119
|
'value' => $attributes['products_options_values'],
|
|
120
|
'prefix' => $attributes['price_prefix'],
|
|
121
|
'price' => $attributes['options_values_price']);
|
|
122
|
|
|
123
|
$subindex++;
|
|
124
|
}
|
|
125
|
}
|
|
126
|
|
|
127
|
$this->info['tax_groups']["{$this->products[$index]['tax']}"] = '1';
|
|
128
|
|
|
129
|
$index++;
|
|
130
|
}
|
|
131
|
}
|
|
132
|
|
|
133
|
function cart() {
|
|
134
|
global $osC_Session, $osC_Customer, $osC_Tax, $cart, $osC_Currencies;
|
|
135
|
|
|
136
|
$this->content_type = $cart->get_content_type();
|
|
137
|
|
|
138
|
$shipping =& $osC_Session->value('shipping');
|
|
139
|
$payment =& $osC_Session->value('payment');
|
|
140
|
|
|
141
|
$customer_address_query = tep_db_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 = '" . (int)$osC_Customer->id . "' and ab.customers_id = '" . (int)$osC_Customer->id . "' and c.customers_default_address_id = ab.address_book_id");
|
|
142
|
$customer_address = tep_db_fetch_array($customer_address_query);
|
|
143
|
|
|
144
|
$shipping_address_query = tep_db_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 = '" . (int)$osC_Customer->id . "' and ab.address_book_id = '" . (int)$osC_Session->value('sendto') . "'");
|
|
145
|
$shipping_address = tep_db_fetch_array($shipping_address_query);
|
|
146
|
|
|
147
|
$billing_address_query = tep_db_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 = '" . (int)$osC_Customer->id . "' and ab.address_book_id = '" . (int)$osC_Session->value('billto') . "'");
|
|
148
|
$billing_address = tep_db_fetch_array($billing_address_query);
|
|
149
|
|
|
150
|
$tax_address_query = tep_db_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 = '" . (int)$osC_Customer->id . "' and ab.address_book_id = '" . (int)($this->content_type == 'virtual' ? $osC_Session->value('billto') : $osC_Session->value('sendto')) . "'");
|
|
151
|
$tax_address = tep_db_fetch_array($tax_address_query);
|
|
152
|
|
|
153
|
$this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID,
|
|
154
|
'currency' => $osC_Session->value('currency'),
|
|
155
|
'currency_value' => $osC_Currencies->currencies[$osC_Session->value('currency')]['value'],
|
|
156
|
'payment_method' => $payment,
|
|
157
|
'cc_type' => (isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : ''),
|
|
158
|
'cc_owner' => (isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : ''),
|
|
159
|
'cc_number' => (isset($GLOBALS['cc_number']) ? $GLOBALS['cc_number'] : ''),
|
|
160
|
'cc_expires' => (isset($GLOBALS['cc_expires']) ? $GLOBALS['cc_expires'] : ''),
|
|
161
|
'shipping_method' => $shipping['title'],
|
|
162
|
'shipping_cost' => $shipping['cost'],
|
|
163
|
'subtotal' => 0,
|
|
164
|
'tax' => 0,
|
|
165
|
'tax_groups' => array(),
|
|
166
|
'comments' => ($osC_Session->exists('comments') ? $osC_Session->value('comments') : ''));
|
|
167
|
|
|
168
|
if (isset($GLOBALS[$payment]) && is_object($GLOBALS[$payment])) {
|
|
169
|
$this->info['payment_method'] = $GLOBALS[$payment]->title;
|
|
170
|
|
|
171
|
if ( isset($GLOBALS[$payment]->order_status) && is_numeric($GLOBALS[$payment]->order_status) && ($GLOBALS[$payment]->order_status > 0) ) {
|
|
172
|
$this->info['order_status'] = $GLOBALS[$payment]->order_status;
|
|
173
|
}
|
|
174
|
}
|
|
175
|
|
|
176
|
$this->customer = array('firstname' => $customer_address['customers_firstname'],
|
|
177
|
'lastname' => $customer_address['customers_lastname'],
|
|
178
|
'company' => $customer_address['entry_company'],
|
|
179
|
'street_address' => $customer_address['entry_street_address'],
|
|
180
|
'suburb' => $customer_address['entry_suburb'],
|
|
181
|
'city' => $customer_address['entry_city'],
|
|
182
|
'postcode' => $customer_address['entry_postcode'],
|
|
183
|
'state' => ((tep_not_null($customer_address['entry_state'])) ? $customer_address['entry_state'] : $customer_address['zone_name']),
|
|
184
|
'zone_id' => $customer_address['entry_zone_id'],
|
|
185
|
'country' => array('id' => $customer_address['countries_id'], 'title' => $customer_address['countries_name'], 'iso_code_2' => $customer_address['countries_iso_code_2'], 'iso_code_3' => $customer_address['countries_iso_code_3']),
|
|
186
|
'format_id' => $customer_address['address_format_id'],
|
|
187
|
'telephone' => $customer_address['customers_telephone'],
|
|
188
|
'email_address' => $customer_address['customers_email_address']);
|
|
189
|
|
|
190
|
$this->delivery = array('firstname' => $shipping_address['entry_firstname'],
|
|
191
|
'lastname' => $shipping_address['entry_lastname'],
|
|
192
|
'company' => $shipping_address['entry_company'],
|
|
193
|
'street_address' => $shipping_address['entry_street_address'],
|
|
194
|
'suburb' => $shipping_address['entry_suburb'],
|
|
195
|
'city' => $shipping_address['entry_city'],
|
|
196
|
'postcode' => $shipping_address['entry_postcode'],
|
|
197
|
'state' => ((tep_not_null($shipping_address['entry_state'])) ? $shipping_address['entry_state'] : $shipping_address['zone_name']),
|
|
198
|
'zone_id' => $shipping_address['entry_zone_id'],
|
|
199
|
'country' => array('id' => $shipping_address['countries_id'], 'title' => $shipping_address['countries_name'], 'iso_code_2' => $shipping_address['countries_iso_code_2'], 'iso_code_3' => $shipping_address['countries_iso_code_3']),
|
|
200
|
'country_id' => $shipping_address['entry_country_id'],
|
|
201
|
'format_id' => $shipping_address['address_format_id']);
|
|
202
|
|
|
203
|
$this->billing = array('firstname' => $billing_address['entry_firstname'],
|
|
204
|
'lastname' => $billing_address['entry_lastname'],
|
|
205
|
'company' => $billing_address['entry_company'],
|
|
206
|
'street_address' => $billing_address['entry_street_address'],
|
|
207
|
'suburb' => $billing_address['entry_suburb'],
|
|
208
|
'city' => $billing_address['entry_city'],
|
|
209
|
'postcode' => $billing_address['entry_postcode'],
|
|
210
|
'state' => ((tep_not_null($billing_address['entry_state'])) ? $billing_address['entry_state'] : $billing_address['zone_name']),
|
|
211
|
'zone_id' => $billing_address['entry_zone_id'],
|
|
212
|
'country' => array('id' => $billing_address['countries_id'], 'title' => $billing_address['countries_name'], 'iso_code_2' => $billing_address['countries_iso_code_2'], 'iso_code_3' => $billing_address['countries_iso_code_3']),
|
|
213
|
'country_id' => $billing_address['entry_country_id'],
|
|
214
|
'format_id' => $billing_address['address_format_id']);
|
|
215
|
|
|
216
|
$index = 0;
|
|
217
|
$products = $cart->get_products();
|
|
218
|
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
|
|
219
|
$this->products[$index] = array('qty' => $products[$i]['quantity'],
|
|
220
|
'name' => $products[$i]['name'],
|
|
221
|
'model' => $products[$i]['model'],
|
|
222
|
'tax' => $osC_Tax->getTaxRate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']),
|
|
223
|
'tax_description' => $osC_Tax->getTaxRateDescription($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']),
|
|
224
|
'tax_class_id' => $products[$i]['tax_class_id'],
|
|
225
|
'price' => $products[$i]['price'],
|
|
226
|
'final_price' => $products[$i]['price'] + $cart->attributes_price($products[$i]['id']),
|
|
227
|
'weight' => $products[$i]['weight'],
|
|
228
|
'id' => $products[$i]['id']);
|
|
229
|
|
|
230
|
if ($products[$i]['attributes']) {
|
|
231
|
$subindex = 0;
|
|
232
|
reset($products[$i]['attributes']);
|
|
233
|
while (list($option, $value) = each($products[$i]['attributes'])) {
|
|
234
|
$attributes_query = tep_db_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 = '" . (int)$products[$i]['id'] . "' and pa.options_id = '" . (int)$option . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . (int)$value . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . (int)$osC_Session->value('languages_id') . "' and poval.language_id = '" . (int)$osC_Session->value('languages_id') . "'");
|
|
235
|
$attributes = tep_db_fetch_array($attributes_query);
|
|
236
|
|
|
237
|
$this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options_name'],
|
|
238
|
'value' => $attributes['products_options_values_name'],
|
|
239
|
'option_id' => $option,
|
|
240
|
'value_id' => $value,
|
|
241
|
'prefix' => $attributes['price_prefix'],
|
|
242
|
'price' => $attributes['options_values_price']);
|
|
243
|
|
|
244
|
$subindex++;
|
|
245
|
}
|
|
246
|
}
|
|
247
|
|
|
248
|
$shown_price = tep_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'];
|
|
249
|
$this->info['subtotal'] += $shown_price;
|
|
250
|
|
|
251
|
$products_tax = $this->products[$index]['tax'];
|
|
252
|
$products_tax_description = $this->products[$index]['tax_description'];
|
|
253
|
if (DISPLAY_PRICE_WITH_TAX == 'true') {
|
|
254
|
$this->info['tax'] += $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)));
|
|
255
|
if (isset($this->info['tax_groups']["$products_tax_description"])) {
|
|
256
|
$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)));
|
|
257
|
} else {
|
|
258
|
$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)));
|
|
259
|
}
|
|
260
|
} else {
|
|
261
|
$this->info['tax'] += ($products_tax / 100) * $shown_price;
|
|
262
|
if (isset($this->info['tax_groups']["$products_tax_description"])) {
|
|
263
|
$this->info['tax_groups']["$products_tax_description"] += ($products_tax / 100) * $shown_price;
|
|
264
|
} else {
|
|
265
|
$this->info['tax_groups']["$products_tax_description"] = ($products_tax / 100) * $shown_price;
|
|
266
|
}
|
|
267
|
}
|
|
268
|
|
|
269
|
$index++;
|
|
270
|
}
|
|
271
|
|
|
272
|
if (DISPLAY_PRICE_WITH_TAX == 'true') {
|
|
273
|
$this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
|
|
274
|
} else {
|
|
275
|
$this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
|
|
276
|
}
|
|
277
|
}
|
|
278
|
}
|
|
279
|
?>
|