国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

通過AJAX方式動態更新ecshop購物車頁面的商品數量

2024-04-25 20:40:49
字體:
來源:轉載
供稿:網友

每次用戶進入ecshop購物流程的時候當需要更改購物車里的商品數量的時候必須要手動點擊更新按鈕,這是非常糟糕的用戶體驗,我們有必要去改進這一點。

以下是通過AJAX方式來動態更新ECShop購物車頁面商品數量的解決辦法

一、前端頁面部分(flow.dwt)

在商品數量的input框添加對應的js函數

<INPUT onblur=”changePrice(document.getElementById(‘goods_number_{$goods.rec_id}’).value,{$goods.rec_id})” name=”goods_number[{$goods.rec_id}]” id=”goods_number_{$goods.rec_id}” value=”{$goods.goods_number}” id=”ECS_FORMBUY”>

在文件最后添加一段js

<script type=”text/javascript”>

function changePrice(number,rec_id)

{

var attr = getSelectedAttributes(document.forms['ECS_FORMBUY']);

var qty = document.forms['ECS_FORMBUY'].elements['number'].value;

Ajax.call(‘flow.php’, ‘step=update_group_cart&rec_id=’ + rec_id +’&number=’ + number, changePriceResponse, ‘GET’, ‘JSON’);

}

function changePriceResponse(res)

{

if (res.error > 0)

{

document.getElementById(‘sysmsg_error’).innerHTML = res.content;

document.all.sysmsg_error.style.display=”;

}

else

{

if(document.all.sysmsg_error.style.display==”)

{

document.all.sysmsg_error.style.display=’none’;

}

document.getElementById(‘subtotal_’+res.rec_id).innerHTML = res.subtotal;

document.getElementById(‘cart_amount’).innerHTML = res.cart_amount;

}

}

</script>

二、在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的緩存刷新頁面看看效果吧。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 景宁| 泌阳县| 舞阳县| 深水埗区| 新泰市| 兰溪市| 银川市| 万载县| 南投市| 敦化市| 改则县| 渝北区| 宁德市| 成都市| 景宁| 鸡泽县| 中西区| 三门峡市| 文安县| 岐山县| 山阳县| 宿州市| 林口县| 仁化县| 襄樊市| 永登县| 文山县| 龙里县| 平潭县| 金塔县| 兰州市| 赣州市| 泽普县| 中宁县| 金堂县| 容城县| 湟源县| 泸溪县| 和静县| 新乡市| 巴塘县|