之前已经在后台html目录里建立了account.point.php的文件,前台菜单生产一个链 接,page=account.point&option=com_virtuemart 就可以读取到这个页面。数据库里,我在jos_vm_orders里添加了point字段,并修改了ps_checkout文件,这样在生成订单时,积分 就可以根据订单的总额产生积分并插入到数据库里。因为有的时候需要做双倍积分活动,所以后台还需添加双倍积分的开关。现在所需就是应该新建一个表,当订单 完成支付后,订单状态变成confirm确认状态时,需要将积分插入到这个表里,这样积分就开始处于冻结状态。当订单处理发货后,那应该将解冻日期插入进 去。
插入了数据库的表
CREATE TABLE IF NOT EXISTS `jos_vm_points` (
`point_id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) NOT NULL DEFAULT '0',
`cdate` int(11) DEFAULT NULL,
`mdate` int(11) DEFAULT NULL,
PRIMARY KEY (`point_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Used to store all points' AUTO_INCREMENT=1 ;
然后就是对,class里面的ps_order.php里面的函数作了 function order_status_update(&$d) {
global $mosConfig_offset;
global $sess, $VM_LANG, $vmLogger;
$db = new ps_DB;
//$timestamp = time() + ($mosConfig_offset*60*60); //Original
$timestamp = time(); //Custom
//$mysqlDatetime = date("Y-m-d G:i:s",$timestamp); //Original
$mysqlDatetime = date("Y-m-d G:i:s", $timestamp + ($mosConfig_offset*60*60)); //Custom
if( empty($_REQUEST['include_comment'])) {
$include_comment="N";
}
// get the current order status
$curr_order_status = @$d["current_order_status"];
$notify_customer = empty($d['notify_customer']) ? "N" : $d['notify_customer'];
if( $notify_customer=="Y" ) {
$notify_customer=1;
}
else {
$notify_customer=0;
}
$d['order_comment'] = empty($d['order_comment']) ? "" : $d['order_comment'];
if( empty($d['order_item_id']) ) {
// When the order is set to "confirmed", we can capture
// the Payment with authorize.net
if( $curr_order_status=="P" && $d["order_status"]=="C") {
$q = "SELECT order_number,payment_class,order_payment_trans_id FROM #__{vm}_payment_method,#__{vm}_order_payment,#__{vm}_orders WHERE ";
$q .= "#__{vm}_order_payment.order_id='".$db->getEscaped($d['order_id'])."' ";
$q .= "AND #__{vm}_orders.order_id='".$db->getEscaped($d['order_id'])."' ";
$q .= "AND #__{vm}_order_payment.payment_method_id=#__{vm}_payment_method.payment_method_id";
$db->query( $q );
$db->next_record();
$payment_class = $db->f("payment_class");
$d["order_number"] = $db->f("order_number");
switch( $payment_class ) {
case "ps_authorize":
require_once( CLASSPATH."payment/ps_authorize.cfg.php");
if( AN_TYPE == 'AUTH_ONLY' ) {
require_once( CLASSPATH."payment/ps_authorize.php");
$authorize = new ps_authorize();
if( !$authorize->capture_payment( $d )) {
return false;
}
}
break;
default:
// default case for payment methods that allow to "capture" the payment
if( is_file( CLASSPATH.'payment/'.basename($payment_class).'.php' ) ) {
require_once( CLASSPATH.'payment/'.basename($payment_class).'.php' );
if( !class_exists($payment_class)) break;
$paymentObj = new $payment_class();
if( !method_exists($paymentObj,'capture_payment')) break;
if( !$paymentObj->capture_payment( $d )) {
return false;
}
}
break;
}
$query = "SELECT * FROM #__{vm}_points WHERE order_id =".$d["order_id"];
$db->query( $query);
if (!$db->next_record()){
$fields = array( 'point_status_code' =>'N',
'order_id' => $d["order_id"],
'cdate' => $timestamp,
'mdate' => $timestamp
);
$db->buildQuery('INSERT', '#__{vm}_points', $fields );
$db->query();
}
}
/*
* This is like the test above for delayed capture only
* we (well, I - durian) don't think the credit card
* should be captured until the item(s) are shipped.
* In fact, VeriSign says not to capture the cards until
* the item ships. Maybe this behavior should be a
* configurable item?
*
* When the order changes from Confirmed or Pending to
* Shipped, perform the delayed capture.
*
* Restricted to PayFlow Pro for now.
*/
if( ($curr_order_status=="P" || $curr_order_status=="C") && $d["order_status"]=="S") {
$q = "SELECT order_number,payment_class,order_payment_trans_id FROM #__{vm}_payment_method,#__{vm}_order_payment,#__{vm}_orders WHERE ";
$q .= "#__{vm}_order_payment.order_id='".$db->getEscaped($d['order_id'])."' ";
$q .= "AND #__{vm}_orders.order_id='".$db->getEscaped($d['order_id'])."' ";
$q .= "AND #__{vm}_order_payment.payment_method_id=#__{vm}_payment_method.payment_method_id";
$db->query( $q );
$db->next_record();
$payment_class = $db->f("payment_class");
if( $payment_class=="payflow_pro" ) {
require_once( CLASSPATH."payment/payflow_pro.cfg.php");
if( PFP_TYPE == 'A' ) {
require_once( CLASSPATH."payment/payflow_pro.php");
$pfp = new ps_pfp();
$d["order_number"] = $db->f("order_number");
if( !$pfp->capture_payment( $d )) {
return false;
}
}
}
$query = "SELECT * FROM #__{vm}_points WHERE order_id ='" . $db->getEscaped($d["order_id"]) . "'";
$db->query( $query);
if (!$db->next_record()){
$fields = array( 'point_status_code' =>'Y',
'order_id' => $d["order_id"],
'cdate' => $timestamp,
'mdate' => $timestamp
);
$db->buildQuery('INSERT', '#__{vm}_points', $fields );
$db->query();
}else{
$fields = array( 'point_status_code' =>'Y',
'order_id' => $d["order_id"],
'cdate' => $timestamp,
'mdate' => $timestamp
);
$db->buildQuery('UPDATE', '#__{vm}_points', $fields, "WHERE order_id='" . $db->getEscaped($d["order_id"]) . "'");
$db->query();
}
}
/**
* Do capture when product is shipped
*/
/*
if(($curr_order_status == "P" || $curr_order_status == "C") && $d["order_status"]=="S")
{
$q = "SELECT order_number,payment_class,order_payment_trans_id FROM #__{vm}_payment_method,#__{vm}_order_payment,#__{vm}_orders WHERE ";
$q .= "#__{vm}_orders.order_id='".$db->getEscaped($d['order_id'])."' ";
$q .= "AND #__{vm}_orders.order_id=#__{vm}_order_payment.order_id ";
$q .= "AND #__{vm}_order_payment.payment_method_id=#__{vm}_payment_method.payment_method_id";
$db->query( $q );
$db->next_record();
$payment_class = strtolower(basename($db->f("payment_class")));
if( file_exists( CLASSPATH.'payment/'.$payment_class.'.php' )) {
require_once( CLASSPATH."payment/$payment_class.php");
$payment = new $payment_class();
$d["order_number"] = $db->f("order_number");
if( is_callable( array( $payment, 'capture_payment' ))) {
if( !$payment->capture_payment( $d )) {
return false;
}
}
}
}*/
/*
* If a pending order gets cancelled, void the authorization.
*
* It might work on captured cards too, if we want to
* void shipped orders.
*
*/
if( $curr_order_status=="P" && $d["order_status"]=="X") {
$q = "SELECT order_number,payment_class,order_payment_trans_id FROM #__{vm}_payment_method,#__{vm}_order_payment,#__{vm}_orders WHERE ";
$q .= "#__{vm}_order_payment.order_id='".$db->getEscaped($d['order_id'])."' ";
$q .= "AND #__{vm}_orders.order_id='".$db->getEscaped($d['order_id'])."' ";
$q .= "AND #__{vm}_order_payment.payment_method_id=#__{vm}_payment_method.payment_method_id";
$db->query( $q );
$db->next_record();
$payment_class = strtolower(basename($db->f("payment_class")));
if( file_exists( CLASSPATH.'payment/'.$payment_class.'.php' )) {
require_once( CLASSPATH."payment/$payment_class.php");
$payment = new $payment_class();
$d["order_number"] = $db->f("order_number");
if( is_callable( array( $payment, 'void_authorization' ))) {
if( !$payment->void_authorization( $d )) {
return false;
}
}
}
}
// Do a Refund
if( $d['order_status']=='R' && $curr_order_status != 'R') {
$vmLogger->debug("Initiating Refund");
$q = 'SELECT order_number,payment_class,order_payment_trans_id FROM #__{vm}_payment_method,#__{vm}_order_payment,#__{vm}_orders WHERE ';
$q .= '#__{vm}_orders.order_id=\''.$db->getEscaped($d['order_id']).'\' ';
$q .= 'AND #__{vm}_orders.order_id=#__{vm}_order_payment.order_id ';
$q .= 'AND #__{vm}_order_payment.payment_method_id=#__{vm}_payment_method.payment_method_id';
$db->query( $q );
$db->next_record();
$payment_class = strtolower(basename($db->f("payment_class")));
$vmLogger->debug('Payment Class: '.$payment_class);
if( file_exists( CLASSPATH.'payment/'.$payment_class.'.php' )) {
$vmLogger->debug('Found Payment Module');
require_once( CLASSPATH."payment/$payment_class.php");
$payment = new $payment_class();
$d["order_number"] = $db->f("order_number");
if( is_callable( array( $payment, 'do_refund' )))
{
$vmLogger->debug('Can call do_refund');
if( !$payment->do_refund( $d )) {
$vmLogger->debug('failed to do refund');
return false;
}
}
}
$query = "SELECT * FROM #__{vm}_points WHERE order_id ='" . $db->getEscaped($d["order_id"]) . "'";
$db->query( $query);
if ($db->next_record()){
$query =" DELETE FROM #__{vm}_points WHERE order_id ='" . $db->getEscaped($d["order_id"]) . "'";
$db->query($query);
$db->next_record();
}
}
$fields =array( 'order_status'=> $d["order_status"],
'mdate'=> $timestamp );
$db->buildQuery('UPDATE', '#__{vm}_orders', $fields, "WHERE order_id='" . $db->getEscaped($d["order_id"]) . "'");
$db->query();
// Update the Order History.
$fields = array( 'order_id' => $d["order_id"],
'order_status_code' => $d["order_status"],
'date_added' => $mysqlDatetime,
'customer_notified' => $notify_customer,
'comments' => $d['order_comment']
);
$db->buildQuery('INSERT', '#__{vm}_order_history', $fields );
$db->query();
// Do we need to re-update the Stock Level?
if( (strtoupper($d["order_status"]) == "X" || strtoupper($d["order_status"])=="R")
// && CHECK_STOCK == '1'
&& $curr_order_status != $d["order_status"]
) {
// Get the order items and update the stock level
// to the number before the order was placed
$q = "SELECT product_id, product_quantity FROM #__{vm}_order_item WHERE order_id='".$db->getEscaped($d["order_id"])."'";
$db->query( $q );
$dbu = new ps_DB;
require_once( CLASSPATH.'ps_product.php');
// Now update each ordered product
while( $db->next_record() ) {
if( ENABLE_DOWNLOADS == '1' && ps_product::is_downloadable($db->f("product_id")) && VM_DOWNLOADABLE_PRODUCTS_KEEP_STOCKLEVEL == '1') {
$q = "UPDATE #__{vm}_product
SET product_sales=product_sales-".$db->f("product_quantity")."
WHERE product_id=".$db->f("product_id");
$dbu->query( $q );
}
else {
$q = "UPDATE #__{vm}_product
SET product_in_stock=product_in_stock+".$db->f("product_quantity").",
product_sales=product_sales-".$db->f("product_quantity")."
WHERE product_id=".$db->f("product_id");
$dbu->query( $q );
}
}
$query = "SELECT * FROM #__{vm}_points WHERE order_id ='" . $db->getEscaped($d["order_id"]) . "'";
$db->query( $query);
if ($db->next_record()){
$query =" DELETE FROM #__{vm}_points WHERE order_id ='" . $db->getEscaped($d["order_id"]) . "'";
$db->query($query);
$db->next_record();
}
}
// Update the Order Items' status
$q = "SELECT order_item_id FROM #__{vm}_order_item WHERE order_id=".$db->getEscaped($d['order_id']);
$db->query($q);
$dbu = new ps_DB;
while ($db->next_record()) {
$item_id = $db->f("order_item_id");
$fields =array( 'order_status'=> $d["order_status"],
'mdate'=> $timestamp );
$dbu->buildQuery('UPDATE', '#__{vm}_order_item', $fields, "WHERE order_item_id='" .(int)$item_id . "'");
$dbu->query();
}
if (ENABLE_DOWNLOADS == '1') {
##################
## DOWNLOAD MOD
$this->mail_download_id( $d );
}
if( !empty($notify_customer) ) {
$this->notify_customer( $d );
}
} elseif( !empty($d['order_item_id'])) {
// Update the Order Items' status
$q = "SELECT order_item_id, product_id, product_quantity FROM #__{vm}_order_item
WHERE order_id=".$db->getEscaped($d['order_id'])
. ' AND order_item_id='.intval( $d['order_item_id'] );
$db->query($q);
$item_product_id = $db->f('product_id');
$item_product_quantity = $db->f('product_quantity');
require_once( CLASSPATH. 'ps_product.php' );
if( ENABLE_DOWNLOADS == '1' && ps_product::is_downloadable($item_product_id) && VM_DOWNLOADABLE_PRODUCTS_KEEP_STOCKLEVEL == '1') {
$q = "UPDATE #__{vm}_product
SET product_sales=product_sales-".$item_product_quantity."
WHERE product_id=".$item_product_id;
$db->query( $q );
}
else {
$q = "UPDATE #__{vm}_product
SET product_in_stock=product_in_stock+".$item_product_quantity.",
product_sales=product_sales-".$item_product_quantity."
WHERE product_id=".$item_product_id;
$db->query( $q );
}
$fields =array( 'order_status'=> $d["order_status"],作了更改。这样在状态改变时,会相应的在积分表里进行相应操作
'mdate'=> $timestamp );
$db->buildQuery('UPDATE', '#__{vm}_order_item', $fields, 'WHERE order_item_id='.intval( $d['order_item_id'] ));
return $db->query() !== false;
}
return true;
}
注:本文转载自

