ecshop教程:通过AJAX方式动态更新ecshop购物车页面的商品数量

2016-07-16 801

ecshop教程:通过AJAX方式动态更新ecshop购物车页面的商品数量!每次用户进入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的缓存刷新页面看看效果吧。

声明: 本站仅提供资源学习下载,资源费用仅为赞助站长的整理费,不代表资源自身价值也不包含任何服务。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
本站提供的资源来自网络,版权争议与本站无关,所有内容及软件的文章仅限用于学习和研究目的。
如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。侵删请致信E-mail:duhaomu@163.com

浩沐资源网 ecshop技巧 ecshop教程:通过AJAX方式动态更新ecshop购物车页面的商品数量 https://www.dhaomu.com/5513.html

相关文章

发表评论
暂无评论
  • 0 +

    访问总数

  • 0 +

    会员总数

  • 0 +

    文章总数

  • 0 +

    今日发布

  • 0 +

    本周发布

  • 0 +

    运行天数

浩沐资源网-打造全网优质免费教程资源分享网站!