⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ps_checkout.inc

📁 phpShop是一个基于php的分布式电子商务模块
💻 INC
📖 第 1 页 / 共 3 页
字号:
  ***************************************************************************/   function add(&$d) {     global $auth,       $HTTP_POST_VARS,       $cart,       $ps_vendor_id;       require_once("store/lib/ps_payment_method.inc");       $ps_payment_method = new ps_payment_method;       require_once("product/lib/ps_product.inc");       $ps_product= new ps_product;       require_once("shop/lib/ps_cart.inc");       $ps_cart = new ps_cart;     $db = new ps_DB;               if (!$this->validate_form($d)) {       return False;     }          if (!$this->validate_add($d)) {       return False;     }     $order_number = $this->get_order_number();     $order_subtotal = $this->calc_order_subtotal($d);     $order_taxable = $this->calc_order_taxable($d);     $order_tax = $this->calc_order_tax($order_taxable, $d);     $order_shipping = $this->calc_order_shipping($d);     $order_shipping_tax = $this->calc_order_shipping_tax($d);          $timestamp = time();          $order_total = $order_subtotal + $order_tax + $order_shipping + $order_shipping_tax;     $order_total = sprintf("%.2f", $order_total);     // Check to see if Cybercash Processing is wanted for this payment method     if (($ps_payment_method->get_field($d["payment_method_id"], "enable_processor") == "Y") && CC_ENABLE) {       if (!$this->cybercash_process($order_number, $order_total, $d)) {	       return False;       }     }     elseif (($ps_payment_method->get_field($d["payment_method_id"], "enable_processor") == "Y") && AN_ENABLE) {       if (!$this->authnet_process($order_number, $order_total, $d)) {	       return False;       }     }     else {       $d["order_payment_log"] = "Payment information captured for later processing.<BR>";       $d["order_status"] = 'P';     }          /* Insert the main order information */     $q = "INSERT INTO orders ";     $q .= "(user_id, vendor_id, order_number, user_info_id, ";     $q .= "ship_method_id, order_subtotal, order_tax, order_shipping, ";     $q .= "order_shipping_tax, order_currency, order_status, cdate, ";     $q .= "mdate) ";     $q .= "VALUES (";     $q .= "'" . $auth["user_id"] . "', ";     $q .= $ps_vendor_id . ", ";       $q .= "'" . $order_number . "', ";     $q .= $d["ship_to_info_id"] . ", '";     $q .= $d["ship_method_id"] . "', ";     $q .= $order_subtotal . ", ";     $q .= $order_tax . ", ";      $q .= $order_shipping . ", ";     $q .= $order_shipping_tax . ", ";     $q .= "'', "; /* Currency is at the product level - line item */     $q .= "'" . $d["order_status"] . "', ";     $q .= $timestamp . ", ";     $q .= $timestamp;     $q .= ")";          $db->query($q);     $db->next_record();          /* Get the order id just stored */          $q = "SELECT order_id FROM orders WHERE order_number = ";     $q .= "'" . $order_number . "'";          $db->query($q);     $db->next_record();          $order_id = $db->f("order_id");          /* Insert the Order payment info */          $payment_number = ereg_replace(" |-", "", $d["order_payment_number"]);          // Payment number is encrypted using mySQL ENCODE function.     $q = "INSERT INTO order_payment ";     $q .= "(order_id, payment_method_id, order_payment_number, ";     $q .= "order_payment_expire, order_payment_log, order_payment_name) ";     $q .= "VALUES (";     $q .= $order_id . ", ";     $q .= "'" . $d["payment_method_id"] . "', ";     $q .= "ENCODE(\"$payment_number\",\"" . ENCODE_KEY . "\"), ";     $q .= "'" . $d["order_payment_expire"] . "',";     $q .= "'" . $d["order_payment_log"] . "',";     $q .= "'" . $d["order_payment_name"] . "'";     $q .= ")";     $db->query($q);     $db->next_record();          /* Insert the order line items; one row per product in the cart */     for($i = 0; $i < $cart["idx"]; $i++) {              $product_price_arr = $ps_product->get_price($cart[$i]["product_id"]);              $product_price = $product_price_arr["product_price"];              $vendor_id = $ps_vendor_id;              $product_currency = $product_price_arr["product_currency"];              $q = "INSERT INTO order_item ";       $q .= "(order_id, user_info_id, vendor_id, ";       $q .= "product_id, product_quantity, product_item_price, ";       $q .= "order_item_currency, order_status, cdate, mdate) ";       $q .= "VALUES ('";       $q .= $order_id . "', '";       $q .= $d["ship_to_info_id"] . "', '";       $q .= $vendor_id . "', '";       $q .= $cart[$i]["product_id"] . "', '";       $q .= $cart[$i]["quantity"] . "', '";       $q .= $product_price . "', '";       $q .= $product_currency . "', ";       $q .= "'P','";       $q .= $timestamp . "','";       $q .= $timestamp . "'";       $q .= ")";              $db->query($q);       $db->next_record();     }      for($i = 0; $i < $cart["idx"]; $i++) {      $r = "SELECT product_in_stock ";      $r .= "FROM product where product_id=";      $r .= $cart[$i]["product_id"];      $db->query($r);      $db->next_record();      if ($db->f("product_in_stock")) {       $newquantity=($db->f("product_in_stock")-$cart[$i]["quantity"]);       if ($newquantity <0) $newquantity=0;       $q = "UPDATE product ";       $q .= "SET product_in_stock=$newquantity ";       $q .= "where product_id=";       $q .= $cart[$i]["product_id"];       $db->query($q);       $db->next_record();      }     }           // Export the order_id so the checkout complete page can get it     $d["order_id"] = $order_id;          // Unset the payment_method variables           $d["payment_method_id"] = "";     $d["order_payment_number"] = "";     $d["order_payment_expire"] = "";     $d["order_payment_name"] = "";          $HTTP_POST_VARS["payment_method_id"] = "";     $HTTP_POST_VARS["order_payment_number"] = "";              $HTTP_POST_VARS["order_payment_expire"] = "";     $HTTP_POST_VARS["order_payment_name"] = "";          // Send the e-mail confirmation messages     $this->email_receipt($order_id);     // Reset the cart      $ps_cart->reset();          return True;   }  /**************************************************************************  ** name: get_order_number()  ** created by: gday  ** description:  Create an order number using the session id, session  **               name, and the current unix timestamp.  ** parameters:   ** returns: unique order_number  ***************************************************************************/   function get_order_number() {      global $sess;      /* Generated a unique order number */      $str = (string)$sess->id;      $str .= (string)$sess->name;      $str .= (string)time();      $order_number = md5($str);   return($order_number);   }  /***************************************************************************  ** name: calc_order_taxable()  ** created by: Chris Coleman  ** description:  Calculates the taxable order subtotal for the order.    ** If an item has no weight, it is non taxable.                ** parameters: $d IS_TAX_VIRTUAL  ** returns: taxable dollar value for this order.  ***************************************************************************/   function calc_order_taxable($d) {      global $auth, $cart;      $subtotal = 0.0;       require_once("product/lib/ps_product.inc");       $ps_product= new ps_product;       require_once("zone/lib/ps_zone.inc");       $ps_zone= new ps_zone;           $db = new ps_DB;       for($i = 0; $i < $cart["idx"]; $i++) {            $product_price_arr = $ps_product->get_price($cart[$i]["product_id"]);	    $item_weight = $ps_zone->get_weight($cart[$i]["product_id"]);	    if ($item_weight !=0 or IS_TAX_VIRTUAL) {            $subtotal += $product_price_arr["product_price"] * $cart[$i]["quantity"];            }      }               return($subtotal);    }  /**************************************************************************  ** name: calc_order_subtotal()  ** created by: gday  ** description:  Calculate the order subtotal for the current order.    **               Does not include tax or shipping charges.  ** parameters: $d  ** returns: sub total for this order  ***************************************************************************/   function calc_order_subtotal($d) {      global $auth, $cart;      $subtotal = 0.0;       require_once("product/lib/ps_product.inc");       $ps_product= new ps_product;           $db = new ps_DB;       for($i = 0; $i < $cart["idx"]; $i++) {            $product_price_arr = $ps_product->get_price($cart[$i]["product_id"]);            $subtotal += $product_price_arr["product_price"] * $cart[$i]["quantity"];      }               return($subtotal);    }  /**************************************************************************  ** name: calc_order_tax()  ** created by: pablo  ** description:Calculate the tax charges for the current order.  This is   **             calculating tax based on the ship-to address.  ** parameters: $d  **             $order_subtotal - sub total for the order  ** returns: Tax for the current order  ***************************************************************************/   function calc_order_tax($order_subtotal, $d) {      global $ps_vendor_id;      $db = new ps_DB;              require_once("tax/lib/ps_tax.inc");       $ps_tax= new ps_tax;           $q = "SELECT state, country FROM user_info WHERE user_info_id='";      $q .= $d["ship_to_info_id"] . "'";      $db->query($q);      $db->next_record();       $state = $db->f("state");      $country = $db->f("country");          $q = "SELECT * FROM tax_rate WHERE tax_country='$country' ";      $q .= "AND tax_state='$state'";       $db->query($q);      if ($db->next_record()) {         $rate = $order_subtotal * $db->f("tax_rate");         return $rate;      }      else         return(0);   }   /**************************************************************************     ** name: calc_order_shipping()    ** created by: Mike Wattier <geek@devcompany.com>      ** description:  Calculate the shipping charges for the current order      **                       using zones assigned in the zone module and the     **                       total quantity of items in the cart      ** parameters: $d,      ** returns: Shipping costs for this order based on country     ***************************************************************************/   function calc_order_shipping($d) {   	   	global $ps_vendor_id;   	   	$db = new ps_DB;   	   	$db2 = new ps_DB;  	   	$db3 = new ps_DB; 	   	  	   	$q = "SELECT country FROM user_info WHERE user_info_id='"; 	   	$q .= $d["ship_to_info_id"] . "'";	   	$db->query($q);   	$db->next_record();   	$country = $db->f("country");   	   	   	$q2 = "SELECT zone_id FROM zone_country WHERE country_3_code='$country' ";  	   	$db2->query($q2);	   	$db2->next_record();   	$the_zone = $db2->f("zone_id");	   	   	$q3 = "SELECT * FROM zone_shipping WHERE zone_id ='$the_zone' ";   	$db3->query($q3);   	$db3->next_record(); 	   	   	$cost_low = $db3->f("zone_cost") * $d["zone_qty"];  	   	if($cost_low < $db3->f("zone_limit")) {  		   		return $cost_low; 		   	}  	   	else { 		   		return $db3->f("zone_limit");  		   	} 	   }     /**************************************************************************/        /**************************************************************************  ** name: calc_order_shipping_tax()  ** created by: gday  ** description:  Calculate the tax for the shipping of the current order  ** parameters: $d  ** returns: Tax for the shipping of this order  ***************************************************************************/   function calc_order_shipping_tax($d) {       /* 01/25/2000 - Dummy function for now */      return(0);   }      /**************************************************************************  ** name: get_vendor_currency()  ** created by: gday  ** description:  Get the currency type used by the $vendor_id  ** parameters: $vendor_id - vendor id to return currency type  ** returns: Currency type for this vendor  ***************************************************************************/   function get_vendor_currency($vendor_id) {      $db = new ps_DB;      $q = "SELECT vendor_currency FROM vendor WHERE vendor_id=$vendor_id";      $db->query($q);      $db->next_record();      $currency = $db->f("vendor_currency");      return($currency);   }  /**************************************************************************  ** name: email_receipt()  ** created by: gday  ** description:  Create a receipt for the current order and email it to   **               the customer and the vendor.  ** parameters: $order_id - Order ID for which to create the email receipts  ** returns:  True - receipt created and emailed  **          False - error occured   ***************************************************************************/   function email_receipt($order_id) {       global $sess,              $ps_product,              $ps_vendor_id;       require_once("product/lib/ps_product.inc");       $ps_product = new ps_product;       // Connect to database and gather appropriate order information       $db = new ps_DB;       $q  = "SELECT * FROM orders ";       $q .= "WHERE order_id='$order_id'";       $db->query($q);       $db->next_record();       $user_id = $db->f("user_id");       $dbbt = new ps_DB;       $qt = "SELECT * from user_info ";       $qt .= "WHERE user_info.user_id='$user_id' ";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -