1

嘿,我有一个 PHP 站点的问题,如果您在结帐中更改数量,小计不会改变。我对 PHP 不是很胜任,所以它可能很简单。这是更新数量的代码;

<?php include_once($_SERVER["DOCUMENT_ROOT"].'/vuengine/viewerlib.php'); ?>

<?php
$listing_num         = $_REQUEST['pd_id'];
$listing_qty         = $_REQUEST['pd_qty'];
$order_num           = $_COOKIE['ordernum'];

echo $order_num;

//Get order details
$order_details     = mysql_select('orders', 'num='.$order_num);
$listings_subtotal = $order_details[0]['listings_subtotal'];

//Get listing details
$listing_details = mysql_select('listings', 'num='.$listing_num);
$seller_num      = $listing_details[0]['member_num'];

//Update order with new shipping
//Get orders_sellers_items unit_price and qty
$order_sellers_item_details = mysql_select('orders_sellers_items',        
'order_num='.$order_num.' AND listing_num='.$listing_num);

//Get unit price
$unit_price     = $order_sellers_item_details[0]['unit_price'];
$qty            = $order_sellers_item_details[0]['qty'];
$shipping_num   = $order_sellers_item_details[0]['shipping_num'];
$shipping_price = $order_sellers_item_details[0]['shipping_price'];

 //Get shipping price
$shipping_price = mysql_select('shipping_rates', 'num='.$shipping_num);
$shipping_price = $shipping_price[0]['charge'];

$new_shipping_total = $shipping_price*$listing_qty;

$new_subtotal = ($unit_price*$listing_qty);

//Update orders_sellers_items with new subtotal
mysql_update('orders_sellers_items', null, 'order_num='.$order_num.' AND     
listing_num='.$listing_num, array('subtotal' => $new_subtotal+$new_shipping_total, 
'qty' => $listing_qty, 'shipping_price' => $shipping_price));


//Update order with new listing_subtotal
$orders_items = mysql_select('orders_sellers_items','order_num='.$order_num);   
$order_subtotal    = 0;    
$shipping_subtotal = 0;
foreach($orders_items as $order_item){
$order_subtotal    +=$order_item['unit_price']*$order_item['qty'];
$shipping_subtotal +=$order_item['shipping_price']*$order_item['qty'];
}

mysql_update('orders', $order_num, null,     
array('listings_subtotal'=>$order_subtotal,     'shipping_subtotal' => 
$shipping_subtotal, 'total' => $order_subtotal+$shipping_subtotal, 'updatedDate=' => 
'NOW()'));

//Get orders_sellers_items for order and seller
$orders_items_seller =     
mysql_select('orders_sellers_items','order_num='.$order_num.'     AND     
seller_num='.$seller_num);  
$order_subtotal2     = 0;
$order_shipping      = 0;
foreach($orders_items_seller as $order_item_seller){
$order_subtotal2 += $order_item_seller['unit_price']*$order_item_seller['qty'];
$order_shipping  += $order_item_seller['shipping_price']*$order_item_seller['qty'];
}

//Update orders_sellers table with new subtotal 
mysql_update('orders_sellers', null, 'order_num='.$order_num.' AND
seller_num='.$seller_num, array('listing_subtotal' => $order_subtotal2, 
'shipping_subtotal' => $order_shipping, 'seller_total' => 
$order_subtotal2+$order_shipping)); 

echo json_encode(array('subtotal' => number_format($new_subtotal+    
($shipping_price*$listing_qty),2), 'cart_total' => 
number_format($order_subtotal+$shipping_subtotal,2)));
?>
4

0 回答 0