[ Index ] |
|
Code source de osCommerce 2.2ms2-060817 |
1 <?php 2 /* 3 $Id: order.php,v 1.33 2003/06/09 22:25:35 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 $languages_id; 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)$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 $customer_id, $sendto, $billto, $cart, $languages_id, $currency, $currencies, $shipping, $payment; 135 136 $this->content_type = $cart->get_content_type(); 137 138 $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)$customer_id . "' and ab.customers_id = '" . (int)$customer_id . "' and c.customers_default_address_id = ab.address_book_id"); 139 $customer_address = tep_db_fetch_array($customer_address_query); 140 141 $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)$customer_id . "' and ab.address_book_id = '" . (int)$sendto . "'"); 142 $shipping_address = tep_db_fetch_array($shipping_address_query); 143 144 $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)$customer_id . "' and ab.address_book_id = '" . (int)$billto . "'"); 145 $billing_address = tep_db_fetch_array($billing_address_query); 146 147 $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)$customer_id . "' and ab.address_book_id = '" . (int)($this->content_type == 'virtual' ? $billto : $sendto) . "'"); 148 $tax_address = tep_db_fetch_array($tax_address_query); 149 150 $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 151 'currency' => $currency, 152 'currency_value' => $currencies->currencies[$currency]['value'], 153 'payment_method' => $payment, 154 'cc_type' => (isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : ''), 155 'cc_owner' => (isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : ''), 156 'cc_number' => (isset($GLOBALS['cc_number']) ? $GLOBALS['cc_number'] : ''), 157 'cc_expires' => (isset($GLOBALS['cc_expires']) ? $GLOBALS['cc_expires'] : ''), 158 'shipping_method' => $shipping['title'], 159 'shipping_cost' => $shipping['cost'], 160 'subtotal' => 0, 161 'tax' => 0, 162 'tax_groups' => array(), 163 'comments' => (isset($GLOBALS['comments']) ? $GLOBALS['comments'] : '')); 164 165 if (isset($GLOBALS[$payment]) && is_object($GLOBALS[$payment])) { 166 $this->info['payment_method'] = $GLOBALS[$payment]->title; 167 168 if ( isset($GLOBALS[$payment]->order_status) && is_numeric($GLOBALS[$payment]->order_status) && ($GLOBALS[$payment]->order_status > 0) ) { 169 $this->info['order_status'] = $GLOBALS[$payment]->order_status; 170 } 171 } 172 173 $this->customer = array('firstname' => $customer_address['customers_firstname'], 174 'lastname' => $customer_address['customers_lastname'], 175 'company' => $customer_address['entry_company'], 176 'street_address' => $customer_address['entry_street_address'], 177 'suburb' => $customer_address['entry_suburb'], 178 'city' => $customer_address['entry_city'], 179 'postcode' => $customer_address['entry_postcode'], 180 'state' => ((tep_not_null($customer_address['entry_state'])) ? $customer_address['entry_state'] : $customer_address['zone_name']), 181 'zone_id' => $customer_address['entry_zone_id'], 182 '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']), 183 'format_id' => $customer_address['address_format_id'], 184 'telephone' => $customer_address['customers_telephone'], 185 'email_address' => $customer_address['customers_email_address']); 186 187 $this->delivery = array('firstname' => $shipping_address['entry_firstname'], 188 'lastname' => $shipping_address['entry_lastname'], 189 'company' => $shipping_address['entry_company'], 190 'street_address' => $shipping_address['entry_street_address'], 191 'suburb' => $shipping_address['entry_suburb'], 192 'city' => $shipping_address['entry_city'], 193 'postcode' => $shipping_address['entry_postcode'], 194 'state' => ((tep_not_null($shipping_address['entry_state'])) ? $shipping_address['entry_state'] : $shipping_address['zone_name']), 195 'zone_id' => $shipping_address['entry_zone_id'], 196 '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']), 197 'country_id' => $shipping_address['entry_country_id'], 198 'format_id' => $shipping_address['address_format_id']); 199 200 $this->billing = array('firstname' => $billing_address['entry_firstname'], 201 'lastname' => $billing_address['entry_lastname'], 202 'company' => $billing_address['entry_company'], 203 'street_address' => $billing_address['entry_street_address'], 204 'suburb' => $billing_address['entry_suburb'], 205 'city' => $billing_address['entry_city'], 206 'postcode' => $billing_address['entry_postcode'], 207 'state' => ((tep_not_null($billing_address['entry_state'])) ? $billing_address['entry_state'] : $billing_address['zone_name']), 208 'zone_id' => $billing_address['entry_zone_id'], 209 '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']), 210 'country_id' => $billing_address['entry_country_id'], 211 'format_id' => $billing_address['address_format_id']); 212 213 $index = 0; 214 $products = $cart->get_products(); 215 for ($i=0, $n=sizeof($products); $i<$n; $i++) { 216 $this->products[$index] = array('qty' => $products[$i]['quantity'], 217 'name' => $products[$i]['name'], 218 'model' => $products[$i]['model'], 219 'tax' => tep_get_tax_rate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 220 'tax_description' => tep_get_tax_description($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 221 'price' => $products[$i]['price'], 222 'final_price' => $products[$i]['price'] + $cart->attributes_price($products[$i]['id']), 223 'weight' => $products[$i]['weight'], 224 'id' => $products[$i]['id']); 225 226 if ($products[$i]['attributes']) { 227 $subindex = 0; 228 reset($products[$i]['attributes']); 229 while (list($option, $value) = each($products[$i]['attributes'])) { 230 $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)$languages_id . "' and poval.language_id = '" . (int)$languages_id . "'"); 231 $attributes = tep_db_fetch_array($attributes_query); 232 233 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options_name'], 234 'value' => $attributes['products_options_values_name'], 235 'option_id' => $option, 236 'value_id' => $value, 237 'prefix' => $attributes['price_prefix'], 238 'price' => $attributes['options_values_price']); 239 240 $subindex++; 241 } 242 } 243 244 $shown_price = tep_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty']; 245 $this->info['subtotal'] += $shown_price; 246 247 $products_tax = $this->products[$index]['tax']; 248 $products_tax_description = $this->products[$index]['tax_description']; 249 if (DISPLAY_PRICE_WITH_TAX == 'true') { 250 $this->info['tax'] += $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax))); 251 if (isset($this->info['tax_groups']["$products_tax_description"])) { 252 $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))); 253 } else { 254 $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))); 255 } 256 } else { 257 $this->info['tax'] += ($products_tax / 100) * $shown_price; 258 if (isset($this->info['tax_groups']["$products_tax_description"])) { 259 $this->info['tax_groups']["$products_tax_description"] += ($products_tax / 100) * $shown_price; 260 } else { 261 $this->info['tax_groups']["$products_tax_description"] = ($products_tax / 100) * $shown_price; 262 } 263 } 264 265 $index++; 266 } 267 268 if (DISPLAY_PRICE_WITH_TAX == 'true') { 269 $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost']; 270 } else { 271 $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost']; 272 } 273 } 274 } 275 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 19:48:25 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |