📄 ps_checkout.inc
字号:
<?php/* * The ps_checkout class * * Copyright (c) Edikon Corporation. All rights reserved. * Distributed under the phpShop Public License (pSPL) Version 1.0. * * $Id: ps_checkout.inc,v 1.6 2000/09/13 16:35:43 pfmartin Exp $ * *//****************************************************************************** CLASS DESCRIPTION* * ps_checkout** The class contains the shop checkout code. It is used to checkout* and order and collect payment information.* * propeties: * class_name: Holds the name of the class. Necessary for PHPLIB.* id: Another PHPLIB required variable.* error: Holds most recent error message set in by a method.** methods:* validate_form: Called to validate the values in checkout_form. * validate_add: Validates the checkout values prior to adding* validate_update: Validate the checkout values prior to updating* update: Update the order in the database* delete: Delete the order in the database* find: Find the order in the database* ship_to_addresses_radio: Get all the user_info Ship To (ST) records * associated with the $user_id and print an HTML * radio check box form element using the retrieved data.* display_address: Print an HTML table displaying the user_info record* for the specified $user_info_id and $address_type.* add: Store the order information in the database* get_order_number: Create an order number using the session id, session* name, and the current unix timestamp.* calc_order_subtotal: Calculate the order subtotal for the current order. * Does not include tax or shipping charges.* calc_order_tax: Calculate the tax charges for the current order.* calc_order_shipping: Calculate the shipping charges for the current order* calc_order_shipping_tax: Calculate the tax for the shipping of the * current order* get_vendor_currency: Get the currency type used by the $vendor_id* email_receipt: Create a receipt for the current order and email it to * the customer and the vendor.* payment_method_type_long_name_display: Print the full name of the * payment method type based off of the $short_name* asterisk_pad: Return $str with all but $display_length at the end as * asterisks.* dropdown_display: Print an HTML dropdown box named $name using $arr to* load the drop down. If $value is in $arr, then $value* will be the selected option in the dropdown.* validate_cc: Validates credit card number format.* to_char_array: Helper method for validate_cc()*************************************************************************/class ps_checkout { var $classname = "ps_checkout"; /************************************************************************** ** name: validate_form() ** created by: gday ** description: Called to validate the form values in checkout_form ** parameters: $d ** returns: True - validation passed ** False - validation failed ***************************************************************************/ function validate_form(&$d) { global $cart, $auth; $db = new ps_DB; eval(load_class("store", "ps_payment_method")); $ps_payment_method = new ps_payment_method; if (!$cart["idx"]) { $q = "SELECT order_id FROM orders WHERE user_id='" . $auth["user_id"] . "' "; $q .= "ORDER BY cdate DESC"; $db->query($q); $db->next_record(); $d["order_id"] = $db->f("order_id"); $d["error"] = ""; return False; } if (trim($d["ship_method_id"]) == "0") { $d["error"] = "Please select a shipping method."; return False; } if (!$d["payment_method_id"]) { $d["error"] = "请选择一种付款方式!"; return False; }// if (!$d["order_payment_name"]) {// $d["error"] = "Please enter the name on the account.";// return False;// }// if(!$ps_payment_method->validate_payment($d["payment_method_id"],$d["order_payment_number"])) {// $d["error"] = "The account number entered is not valid.";// return False;// }// $date = getdate(time());// if ($d["order_payment_expire_year"] < $date["year"] or// ($d["order_payment_expire_year"] == $date["year"] and// $d["order_payment_expire_month"] < $date["mon"])) {// $d["error"] = "错误的日期格式";// return False;// } // calculate the unix timestamp for the specified expiration date // default the day to the 1st $expire_timestamp = mktime(0,0,0,$d["order_payment_expire_month"], 1,$d["order_payment_expire_year"]); $d["order_payment_expire"] = $expire_timestamp; return True; } /************************************************************************** ** name: validate_add() ** created by: gday ** description: Validates the checkout form values prior to adding ** parameters: $d ** returns: True - validation passed ** False - validation failed ***************************************************************************/ function validate_add(&$d) { eval(load_class("store", "ps_payment_method")); $ps_payment_method = new ps_payment_method; if (!$d["ship_to_info_id"]) { $d["error"] = "Please select a ship to address."; return False; } if (!$d["payment_method_id"]) { $d["error"] = "请选择一种付款方式!"; return False; }// if (!$d["order_payment_number"]) {// $d["error"] = "Please enter an account number.";// return False;// }// if(!$ps_payment_method->validate_payment($d["payment_method_id"], // $d["order_payment_number"])) {// $d["error"] = "Invalid account number.";// return False;// } if(!$d["order_payment_expire"]) { $d["error"] = "Please enter the account expiration month."; return False; } return True; } /************************************************************************** ** name: validate_shipto() ** created by: pablo ** description: Validate the checkout shipto values prior to showing confirm page. ** parameters: $d ** returns: True - validation passed ** False - validation failed ***************************************************************************/ function validate_shipto(&$d) { if (!$d["ship_to_info_id"]) { $d["error"] = "Please select a shipping address."; return False; } return True; } /************************************************************************** ** name: update() ** created by: gday ** description: Update the order in the database ** parameters: $d ** returns: True - update succeeded ** False - update failed ***************************************************************************/ function update(&$d) { $db = new ps_DB; $timestamp = time(); if ($this->validate_update($d)) { return True; } else { $d["error"] = $this->error; return False; } } /************************************************************************** ** name: ship_to_address_radio() ** created by: gday ** description: Get all the user_info Ship To (ST) records associated ** with the $user_id and print an HTML radio check box ** form element using the retrieved data. ** parameters: $user_id - user id of to display ship to addresses ** $name - name of the HTML radio element ** $value - If matched, then this radio item will be ** checked ** returns: Prints html radio element to standard out ***************************************************************************/ function ship_to_addresses_radio($user_id, $name, $value) { global $sess; $db = new ps_DB; /* Select all the ship to information for this user id and * order by modification date; most recently changed to oldest */ $q = "SELECT user_info_id FROM user_info "; $q .= "WHERE user_id = '" . $user_id . "' "; $q .= "AND address_type = 'BT' "; $db->query($q); $db->next_record(); $bt_user_info_id = $db->f("user_info_id"); $q = "SELECT user_info_id, address_type_name, user_name, question, "; $q .= "answer, true_name, year, month, dey, "; $q .= "sex, card, email, "; $q .= "company, phone, fax,address,zip,Country,province,duty "; $q .= "FROM user_info "; $q .= "WHERE user_id = '" . $user_id . "' "; $q .= "AND address_type = 'ST' "; $q .= "ORDER by address_type_name, mdate DESC"; $db->query($q); echo "<TABLE BORDER=0 WIDTH=100% CELLPADDING=2 CELLSPACING=0>\n"; echo "<TR>\n"; echo "<TD>\n"; if ($db->num_rows() and $bt_user_info_id != $value) { echo "<INPUT TYPE=radio NAME=$name VALUE=\"$bt_user_info_id\">\n"; } else { echo "<INPUT TYPE=radio NAME=$name VALUE=\"$bt_user_info_id\" CHECKED>\n"; } echo "</TD>\n"; echo "<TD bgcolor=#f0f0f0>\n"; echo "使用注册信息送货.</b></font>\n"; echo "</TD>\n"; echo "</TR>\n"; while($db->next_record()) { echo "<TR>\n"; echo "<TD>\n"; if (!strcmp($value, $db->f("user_info_id"))) { echo "<INPUT TYPE=radio NAME=$name VALUE=" . $db->f("user_info_id") . " CHECKED>\n"; } else { echo "<INPUT TYPE=radio NAME=$name VALUE=" . $db->f("user_info_id") . ">\n"; } echo "</TD>\n"; echo "<TD>\n"; echo "<TABLE width=100% border=0 cellspacing=0 cellpadding=1 bgcolor=#f0f0f0>\n"; echo "<TR>\n"; echo "<TD>\n"; echo "<b>" . $db->f("address_type_name") . "</b> "; $url = SECUREURL . "?page=account/shipto&user_info_id=" . $db->f('user_info_id'); $url .= "&next_page=checkout/index"; echo "(<a href=\""; $sess->purl($url); echo "\">Update Address</a>)\n"; echo "<BR>\n"; echo $db->f("title") . " "; echo $db->f("first_name") . " "; echo $db->f("middle_name") . " "; echo $db->f("last_name") . "\n"; echo "<BR>\n"; if ($db->f("company")) { echo $db->f("company") . "\n"; echo "<BR>\n"; } echo $db->f("address_1") . "\n"; if ($db->f("address_2")) { echo "<BR>"; echo $db->f("address_2"). "\n"; } echo "<BR>\n"; echo $db->f("city"); echo ", "; echo $db->f("state") . " "; echo $db->f("zip") . "\n"; echo "<BR>\n"; echo "Phone:"; echo $db->f("phone_1") . "\n"; echo "<BR>\n"; echo "Fax:"; echo $db->f("fax") . "\n"; echo "</TD>\n"; echo "</TR>\n"; echo "</TABLE>\n"; } echo "</TD>\n"; echo "</TR>\n"; echo "</TABLE>\n"; return(true); } /************************************************************************** ** name: display_address() ** created by: gday ** description: Print an HTML table displaying the user_info record ** for the specified $user_info_id and $address_type. ** parameters: $user_info_id - user info id to display ** $address_type - address type (BT or ST) ** returns: Prints HTML table displaying the address information ***************************************************************************/ function display_address($user_info_id) { $db = new ps_DB; $q = "SELECT address_type_name, company, title, last_name, "; $q .= "first_name, middle_name, phone_1, phone_2, fax, "; $q .= "address_1, address_2, city, state, country, zip "; $q .= "FROM user_info "; $q .= "WHERE user_info_id = '$user_info_id'";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -