|
每次用户进入ecshop购物流程的时候当需要更改购物车里的商品数量的时候必须要手动点击更新按钮,这是非常糟糕的用户体验,我们有必要去改进这一点。
以下是通过AJAX方式来动态更新ECShop购物车页面商品数量的解决办法
一、前端页面部分(flow.dwt)
在商品数量的input框添加对应的js函数
[I,
在文件最后添加一段js
二、在flow.php文件中插入对应的处理代码:
elseif($_REQUEST['step', == ‘update_group_cart’)
{
include_once(‘includes/cls_json.php’);
$json = new JSON();
$result = array(‘error’ => ”, ‘content’ => ”);
$rec_id = $_GET['rec_id',;
$number = $_GET['number',;
$group_buy = group_buy_info($_SESSION['extension_id',, $number);
if(!is_numeric($number))
{
$result['error', = ’1′;
$result['content', =’请输入合法数量’;
die($json->encode($result));
}
if ($group_buy['restrict_amount', > 0 && $number > ($group_buy['restrict_amount', – $group_buy['valid_goods',))
{
$result['error', = ’1′;
$restrict_amount = $group_buy['restrict_amount', – $group_buy['valid_goods',;
$result['content', =’您最多可买’.$restrict_amount.’件’;
die($json->encode($result));
}
$sql = “UPDATE ” . $GLOBALS['ecs',->table(‘cart’) . ” SET goods_number = ‘$number’ WHERE rec_id = $rec_id”;
$GLOBALS['db',->query($sql);
$subtotal = $GLOBALS['db',->getONE(“select goods_price * goods_number AS subtotal from “.$GLOBALS['ecs',->table(‘cart’).” where rec_id = $rec_id”);
$cart_amount = cart_amount(”,$_SESSION['flow_type',);
$result['subtotal', = price_format($subtotal, false);
$result['cart_amount', = price_format($cart_amount, false);
$result['rec_id', = $rec_id;
die($json->encode($result));
}
还等什么?马上清空echsop的缓存刷新页面看看效果吧。 |
|