dongqiya9552 2012-11-05 11:16
浏览 14

checkout qty不会在结帐时更新小计

Hey I have a problem with a site in PHP where if you change the quantity in the checkout the subtotal doesnt change. Im not very competent with PHP so it might be something simple. Here is the code for updating qty;

<?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)));
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?