- 资源介绍
- 更新记录
- 安装教程
通过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的缓存刷新页面看看效果吧。
猜你喜欢
-
ecshop购物流程中支付方式描述不换行的方法
2021-02-04 -
ecshop简化免登录用户的购物收货流量
2021-02-04 -
强化ECSHOP搜索功能(随机关键词+拼音搜索+分词搜索+结果分类展
2021-02-04 -
让ecshop首页分类显示市场价格
2021-02-04 -
ecshop教程:销售排行榜添加上销售出商品的件数
2021-02-04 -
ecshop商品详情页增加已售商品数量和评论数量的方法
2021-02-04 -
Ecshop上传商品图片模糊缩略图不清晰的解决方法
2021-02-04 -
ECSHOP切底删除订单和评论的SQL语法
2021-02-04 -
ecshop无法添加首页主广告的解决方法
2021-02-04 -
ecshop教程:解决会员找回密码无法使用的BUG
2021-02-04
-
关于ECSHOP模板架设的服务器php版本过高报错的解决方法集合
2021-02-04 -
解决ecshop广告位添加不了问题
2021-02-04 -
ecshop商品详情页增加自定义title的方法
2021-02-04 -
ecshop教程:所有配送插件一览表
2021-02-04 -
禁用ecshop缓存,关闭ecshop缓存功能
2021-02-04 -
ecshop教程:显示某商品销售累计效果的实现代码
2021-02-04 -
ecshop无法删除分类的解决方法
2021-02-04 -
修改ecshop后台不提示新版本提示信息
2021-02-04 -
ECshop中defined(‘IN_ECS’)的实现原理
2021-02-04 -
ecshop二次开发网页模板之常用函数汇总
2021-02-04
猜你在找
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载完但解压或打开不了?
- 找不到素材资源介绍文章里的示例图片?
- 大资源
- 2021-02-04Hi,初次和大家见面了,请多关照!
最后编辑:2021-02-04

