[ Index ] |
PHP Cross Reference of osCMax 2.0.4 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 $Id: checkout_process.php 14 2006-07-28 17:42:07Z user $ 4 5 osCMax Power E-Commerce 6 http://oscdox.com 7 8 Copyright 2006 osCMax 9 10 Released under the GNU General Public License 11 */ 12 13 include ('includes/application_top.php'); 14 15 // BOF: Downloads Controller - Free Shipping 16 // Reset $shipping if free shipping is on and weight is not 0 17 if (tep_get_configuration_key_value('MODULE_SHIPPING_FREESHIPPER_STATUS') and $cart->show_weight()!=0) { 18 tep_session_unregister('shipping'); 19 } 20 // EOF: Downloads Controller - Free Shipping 21 // if the customer is not logged on, redirect them to the login page 22 if (!tep_session_is_registered('customer_id')) { 23 $navigation->set_snapshot(array('mode' => 'SSL', 'page' => FILENAME_CHECKOUT_PAYMENT)); 24 tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL')); 25 } 26 27 // if there is nothing in the customers cart, redirect them to the shopping cart page 28 if ($cart->count_contents() < 1) { 29 tep_redirect(tep_href_link(FILENAME_SHOPPING_CART)); 30 } 31 32 // if no shipping method has been selected, redirect the customer to the shipping method selection page 33 if (!tep_session_is_registered('shipping') || !tep_session_is_registered('sendto')) { 34 tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL')); 35 } 36 37 if ( (tep_not_null(MODULE_PAYMENT_INSTALLED)) && (!tep_session_is_registered('payment')) ) { 38 tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); 39 } 40 41 // avoid hack attempts during the checkout procedure by checking the internal cartID 42 if (isset($cart->cartID) && tep_session_is_registered('cartID')) { 43 if ($cart->cartID != $cartID) { 44 tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL')); 45 } 46 } 47 48 include(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_PROCESS); 49 50 // load selected payment module 51 require (DIR_WS_CLASSES . 'payment.php'); 52 // LINE ADDED: MOD - CREDIT CLASS Gift Voucher Contribution 53 if ($credit_covers) $payment=''; 54 $payment_modules = new payment($payment); 55 56 // load the selected shipping module 57 require (DIR_WS_CLASSES . 'shipping.php'); 58 $shipping_modules = new shipping($shipping); 59 60 require (DIR_WS_CLASSES . 'order.php'); 61 $order = new order; 62 63 // Stock Check 64 $any_out_of_stock = false; 65 if (STOCK_CHECK == 'true') { 66 for ($i=0, $n=sizeof($order->products); $i<$n; $i++) { 67 if (tep_check_stock($order->products[$i]['id'], $order->products[$i]['qty'])) { 68 $any_out_of_stock = true; 69 } 70 } 71 // Out of Stock 72 if ( (STOCK_ALLOW_CHECKOUT != 'true') && ($any_out_of_stock == true) ) { 73 tep_redirect(tep_href_link(FILENAME_SHOPPING_CART)); 74 } 75 } 76 77 $payment_modules->update_status(); 78 79 if ( ( is_array($payment_modules->modules) && (sizeof($payment_modules->modules) > 1) && !is_object($$payment) ) || (is_object($$payment) && ($$payment->enabled == false)) ) { 80 tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_NO_PAYMENT_MODULE_SELECTED), 'SSL')); 81 } 82 83 require (DIR_WS_CLASSES . 'order_total.php'); 84 $order_total_modules = new order_total; 85 86 $order_totals = $order_total_modules->process(); 87 88 // load the before_process function from the payment modules 89 $payment_modules->before_process(); 90 91 $sql_data_array = array('customers_id' => $customer_id, 92 'customers_name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'], 93 'customers_company' => $order->customer['company'], 94 'customers_street_address' => $order->customer['street_address'], 95 'customers_suburb' => $order->customer['suburb'], 96 'customers_city' => $order->customer['city'], 97 'customers_postcode' => $order->customer['postcode'], 98 'customers_state' => $order->customer['state'], 99 'customers_country' => $order->customer['country']['title'], 100 'customers_telephone' => $order->customer['telephone'], 101 'customers_email_address' => $order->customer['email_address'], 102 'customers_address_format_id' => $order->customer['format_id'], 103 'delivery_name' => trim($order->delivery['firstname'] . ' ' . $order->delivery['lastname']), 104 'delivery_company' => $order->delivery['company'], 105 'delivery_street_address' => $order->delivery['street_address'], 106 'delivery_suburb' => $order->delivery['suburb'], 107 'delivery_city' => $order->delivery['city'], 108 'delivery_postcode' => $order->delivery['postcode'], 109 'delivery_state' => $order->delivery['state'], 110 'delivery_country' => $order->delivery['country']['title'], 111 'delivery_address_format_id' => $order->delivery['format_id'], 112 'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['lastname'], 113 'billing_company' => $order->billing['company'], 114 'billing_street_address' => $order->billing['street_address'], 115 'billing_suburb' => $order->billing['suburb'], 116 'billing_city' => $order->billing['city'], 117 'billing_postcode' => $order->billing['postcode'], 118 'billing_state' => $order->billing['state'], 119 'billing_country' => $order->billing['country']['title'], 120 'billing_address_format_id' => $order->billing['format_id'], 121 'payment_method' => $order->info['payment_method'], 122 'shipping_module' => $shipping['id'], 123 'cc_type' => $order->info['cc_type'], 124 'cc_owner' => $order->info['cc_owner'], 125 'cc_number' => $order->info['cc_number'], 126 'cc_expires' => $order->info['cc_expires'], 127 'date_purchased' => 'now()', 128 // LINE ADDED: MOD - Downloads Controller 129 'last_modified' => 'now()', 130 'orders_status' => $order->info['order_status'], 131 'currency' => $order->info['currency'], 132 'currency_value' => $order->info['currency_value']); 133 tep_db_perform(TABLE_ORDERS, $sql_data_array); 134 $insert_id = tep_db_insert_id(); 135 for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) { 136 $sql_data_array = array('orders_id' => $insert_id, 137 'title' => $order_totals[$i]['title'], 138 'text' => $order_totals[$i]['text'], 139 'value' => $order_totals[$i]['value'], 140 'class' => $order_totals[$i]['code'], 141 'sort_order' => $order_totals[$i]['sort_order']); 142 tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array); 143 } 144 145 $customer_notification = (SEND_EMAILS == 'true') ? '1' : '0'; 146 $sql_data_array = array('orders_id' => $insert_id, 147 'orders_status_id' => $order->info['order_status'], 148 'date_added' => 'now()', 149 'customer_notified' => $customer_notification, 150 'comments' => $order->info['comments']); 151 tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array); 152 153 // initialized for the email confirmation 154 $products_ordered = ''; 155 $subtotal = 0; 156 $total_tax = 0; 157 158 for ($i=0, $n=sizeof($order->products); $i<$n; $i++) { 159 // Stock Update - Joao Correia 160 // LINE ADDED: MOD - QT Pro 161 $products_stock_attributes=null; 162 if (STOCK_LIMITED == 'true') { 163 // BOF: QT Pro - move from below 164 $products_attributes = $order->products[$i]['attributes']; 165 // BOF: QT Pro - move from below 166 // if (DOWNLOAD_ENABLED == 'true') { 167 // EOF: MOD - QT Pro 168 $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename 169 FROM " . TABLE_PRODUCTS . " p 170 LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa 171 ON p.products_id=pa.products_id 172 LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad 173 ON pa.products_attributes_id=pad.products_attributes_id 174 WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"; 175 // Will work with only one option for downloadable products 176 // otherwise, we have to build the query dynamically with a loop 177 // BOF: QT Pro - move to above 178 // $products_attributes = $order->products[$i]['attributes']; 179 // EOF: QT Pro - move to above 180 if (is_array($products_attributes)) { 181 $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'"; 182 } 183 $stock_query = tep_db_query($stock_query_raw); 184 // BOF: MOD - QT Pro 185 if (tep_db_num_rows($stock_query) > 0) { 186 $stock_values = tep_db_fetch_array($stock_query); 187 $actual_stock_bought = $order->products[$i]['qty']; 188 $download_selected = false; 189 if ((DOWNLOAD_ENABLED == 'true') && isset($stock_values['products_attributes_filename']) && tep_not_null($stock_values['products_attributes_filename'])) { 190 $download_selected = true; 191 $products_stock_attributes='$$DOWNLOAD$$'; 192 } 193 // If not downloadable and attributes present, adjust attribute stock 194 if (!$download_selected && is_array($products_attributes)) { 195 $all_nonstocked = true; 196 $products_stock_attributes_array = array(); 197 foreach ($products_attributes as $attribute) { 198 //**si** 14-11-05 fix missing att list 199 // if ($attribute['track_stock'] == 1) { 200 // $products_stock_attributes_array[] = $attribute['option_id'] . "-" . $attribute['value_id']; 201 $products_stock_attributes_array[] = $attribute['option_id'] . "-" . $attribute['value_id']; 202 if ($attribute['track_stock'] == 1) { 203 //**si** 14-11-05 end 204 $all_nonstocked = false; 205 } 206 } 207 if ($all_nonstocked) { 208 $actual_stock_bought = $order->products[$i]['qty']; 209 //**si** 14-11-05 fix missing att list 210 asort($products_stock_attributes_array, SORT_NUMERIC); 211 $products_stock_attributes = implode(",", $products_stock_attributes_array); 212 //**si** 14-11-05 end 213 214 } else { 215 asort($products_stock_attributes_array, SORT_NUMERIC); 216 $products_stock_attributes = implode(",", $products_stock_attributes_array); 217 $attributes_stock_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); 218 if (tep_db_num_rows($attributes_stock_query) > 0) { 219 $attributes_stock_values = tep_db_fetch_array($attributes_stock_query); 220 $attributes_stock_left = $attributes_stock_values['products_stock_quantity'] - $order->products[$i]['qty']; 221 tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '" . $attributes_stock_left . "' where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); 222 $actual_stock_bought = ($attributes_stock_left < 1) ? $attributes_stock_values['products_stock_quantity'] : $order->products[$i]['qty']; 223 } else { 224 $attributes_stock_left = 0 - $order->products[$i]['qty']; 225 tep_db_query("insert into " . TABLE_PRODUCTS_STOCK . " (products_id, products_stock_attributes, products_stock_quantity) values ('" . tep_get_prid($order->products[$i]['id']) . "', '" . $products_stock_attributes . "', '" . $attributes_stock_left . "')"); 226 $actual_stock_bought = 0; 227 } 228 } 229 } 230 // $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); 231 // } 232 // if (tep_db_num_rows($stock_query) > 0) { 233 // $stock_values = tep_db_fetch_array($stock_query); 234 // do not decrement quantities if products_attributes_filename exists 235 if (!$download_selected) { 236 $stock_left = $stock_values['products_quantity'] - $actual_stock_bought; 237 tep_db_query("UPDATE " . TABLE_PRODUCTS . " 238 SET products_quantity = products_quantity - '" . $actual_stock_bought . "' 239 WHERE products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); 240 // EOF: MOD - QT Pro 241 if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) { 242 tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); 243 } 244 } 245 } 246 // LINE ADDED: MOD - QT Pro 247 } else { 248 if ( is_array($order->products[$i]['attributes']) ) { 249 $products_stock_attributes_array = array(); 250 foreach ($order->products[$i]['attributes'] as $attribute) { 251 $products_stock_attributes_array[] = $attribute['option_id'] . "-" . $attribute['value_id']; 252 } 253 asort($products_stock_attributes_array, SORT_NUMERIC); 254 $products_stock_attributes = implode(",", $products_stock_attributes_array); 255 } 256 } 257 //**si** 14-11-05 end 258 // Update products_ordered (for bestsellers list) 259 tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); 260 // LINE ADDED: MOD - QT Pro 261 if (!isset($products_stock_attributes)) $products_stock_attributes=null; 262 $sql_data_array = array('orders_id' => $insert_id, 263 'products_id' => tep_get_prid($order->products[$i]['id']), 264 'products_model' => $order->products[$i]['model'], 265 'products_name' => $order->products[$i]['name'], 266 'products_price' => $order->products[$i]['price'], 267 'final_price' => $order->products[$i]['final_price'], 268 'products_tax' => $order->products[$i]['tax'], 269 'products_quantity' => $order->products[$i]['qty'],//); 270 // LINE ADDED: MOD - QT Pro 271 'products_stock_attributes' => $products_stock_attributes); 272 tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array); 273 $order_products_id = tep_db_insert_id(); 274 275 // BOF - MOD: CREDIT CLASS Gift Voucher Contribution 276 $order_total_modules->update_credit_account($i); 277 // EOF - MOD: CREDIT CLASS Gift Voucher Contribution 278 279 //------insert customer choosen option to order-------- 280 $attributes_exist = '0'; 281 $products_ordered_attributes = ''; 282 if (isset($order->products[$i]['attributes'])) { 283 $attributes_exist = '1'; 284 for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) { 285 if (DOWNLOAD_ENABLED == 'true') { 286 $attributes_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 287 from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa 288 left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad 289 on pa.products_attributes_id=pad.products_attributes_id 290 where pa.products_id = '" . $order->products[$i]['id'] . "' 291 and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' 292 and pa.options_id = popt.products_options_id 293 and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' 294 and pa.options_values_id = poval.products_options_values_id 295 and popt.language_id = '" . $languages_id . "' 296 and poval.language_id = '" . $languages_id . "'"; 297 $attributes = tep_db_query($attributes_query); 298 } else { 299 $attributes = 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 = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'"); 300 } 301 $attributes_values = tep_db_fetch_array($attributes); 302 303 $sql_data_array = array('orders_id' => $insert_id, 304 'orders_products_id' => $order_products_id, 305 'products_options' => $attributes_values['products_options_name'], 306 // 'products_options_values' => $attributes_values['products_options_values_name'], 307 'products_options_values' => $order->products[$i]['attributes'][$j]['value'], 308 'options_values_price' => $attributes_values['options_values_price'], 309 'price_prefix' => $attributes_values['price_prefix']); 310 tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array); 311 312 if ((DOWNLOAD_ENABLED == 'true') && isset($attributes_values['products_attributes_filename']) && tep_not_null($attributes_values['products_attributes_filename'])) { 313 $sql_data_array = array('orders_id' => $insert_id, 314 'orders_products_id' => $order_products_id, 315 'orders_products_filename' => $attributes_values['products_attributes_filename'], 316 'download_maxdays' => $attributes_values['products_attributes_maxdays'], 317 'download_count' => $attributes_values['products_attributes_maxcount']); 318 tep_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array); 319 } 320 $products_ordered_attributes .= "\n\t" . $attributes_values['products_options_name'] . ' ' . $attributes_values['products_options_values_name']; 321 } 322 } 323 //------insert customer choosen option eof ---- 324 $total_weight += ($order->products[$i]['qty'] * $order->products[$i]['weight']); 325 $total_tax += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty']; 326 $total_cost += $total_products_price; 327 328 $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n"; 329 } 330 331 // LINE ADDED: MOD - CREDIT CLASS Gift Voucher Contribution 332 $order_total_modules->apply_credit(); 333 334 // lets start with the email confirmation 335 // LINE ADDED: PWA - Add test for PWA - no display of invoice URL if PWA customer 336 if (!tep_session_is_registered('noaccount')) { 337 $email_order = STORE_NAME . "\n" . 338 EMAIL_SEPARATOR . "\n" . 339 EMAIL_TEXT_ORDER_NUMBER . ' ' . $insert_id . "\n" . 340 EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $insert_id, 'SSL', false) . "\n" . 341 EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n"; 342 if ($order->info['comments']) { 343 $email_order .= tep_db_output($order->info['comments']) . "\n\n"; 344 } 345 $email_order .= EMAIL_TEXT_PRODUCTS . "\n" . 346 EMAIL_SEPARATOR . "\n" . 347 $products_ordered . 348 EMAIL_SEPARATOR . "\n"; 349 } else { 350 $email_order = STORE_NAME . "\n" . 351 EMAIL_SEPARATOR . "\n" . 352 EMAIL_TEXT_ORDER_NUMBER . ' ' . $insert_id . "\n" . 353 EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n"; 354 if ($order->info['comments']) { 355 $email_order .= tep_db_output($order->info['comments']) . "\n\n"; 356 } 357 $email_order .= EMAIL_TEXT_PRODUCTS . "\n" . 358 EMAIL_SEPARATOR . "\n" . 359 $products_ordered . 360 EMAIL_SEPARATOR . "\n"; 361 } 362 363 for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) { 364 $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n"; 365 } 366 367 if ($order->content_type != 'virtual') { 368 $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . 369 EMAIL_SEPARATOR . "\n" . 370 tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n"; 371 } 372 373 $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" . 374 EMAIL_SEPARATOR . "\n" . 375 tep_address_label($customer_id, $billto, 0, '', "\n") . "\n\n"; 376 if (is_object($$payment)) { 377 $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" . 378 EMAIL_SEPARATOR . "\n"; 379 $payment_class = $$payment; 380 $email_order .= $order->info['payment_method'] . "\n\n"; 381 if ($payment_class->email_footer) { 382 $email_order .= $payment_class->email_footer . "\n\n"; 383 } 384 } 385 tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS); 386 387 // send emails to other people 388 if (SEND_EXTRA_ORDER_EMAILS_TO != '') { 389 tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS); 390 } 391 392 // LINE ADDED: MOD - OSC-AFFILIATE 393 require (DIR_WS_INCLUDES . 'affiliate_checkout_process.php'); 394 395 // remove items from wishlist if customer purchased them 396 $wishList->clear(); 397 398 // load the after_process function from the payment modules 399 $payment_modules->after_process(); 400 401 $cart->reset(true); 402 403 // unregister session variables used during checkout 404 tep_session_unregister('sendto'); 405 tep_session_unregister('billto'); 406 tep_session_unregister('shipping'); 407 tep_session_unregister('payment'); 408 tep_session_unregister('comments'); 409 410 // BOF - MOD: CREDIT CLASS Gift Voucher Contribution 411 if(tep_session_is_registered('credit_covers')) tep_session_unregister('credit_covers'); 412 $order_total_modules->clear_posts(); 413 // EOF - MOD: CREDIT CLASS Gift Voucher Contribution 414 415 tep_redirect(tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL')); 416 417 require (DIR_WS_INCLUDES . 'application_bottom.php'); 418 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Jan 1 13:43:16 2010 | Cross-referenced by PHPXref 0.7 |