ECSHOP系统ajax更新购物车数量
来源:互联网 发布:小米手机关闭移动数据 编辑:程序博客网 时间:2024/06/03 21:06
ECSHOP系统ajax更新购物车数量
- |
- 浏览:1852
- |
- 更新:2013-07-26 09:37
ajax更新购物车数量
方法/步骤
先打开flow.dwt,找到
<!-- {if $goods.goods_id gt 0 && $goods.is_gift eq 0 && $goods.parent_id eq 0} 普通商品可修改数量 -->,把下面的input框里面的替换成<a href="javascript:;" onclick="red_num({$goods.rec_id},{$goods.goods_id});"> - </a><input type="text" name="goods_number[{$goods.rec_id}]" id="goods_number_{$goods.rec_id}" value="{$goods.goods_number}" size="4" class="inputBg" style="text-align:center " onblur="change_price({$goods.rec_id},{$goods.goods_id})"/><a href="javascript:;" onclick='add_num({$goods.rec_id},{$goods.goods_id})' >+</a>
然后在下一个</td>后加一段js代码
<script type="text/javascript" charset="utf-8">
function add_num(rec_id,goods_id)
{
document.getElementById("goods_number_"+rec_id+"").value++;
var number = document.getElementById("goods_number_"+rec_id+"").value;
Ajax.call('flow.php', 'step=update_group_cart&rec_id=' + rec_id +'&number=' + number+'&goods_id=' + goods_id, changePriceResp**e, 'GET', 'JSON');
}
function red_num(rec_id,goods_id)
{
if (document.getElementById("goods_number_"+rec_id+"").value>1)
{
document.getElementById("goods_number_"+rec_id+"").value--;
}
var number = document.getElementById("goods_number_"+rec_id+"").value;
Ajax.call('flow.php', 'step=update_group_cart&rec_id=' + rec_id +'&number=' + number+'&goods_id=' + goods_id, changePriceResp**e, 'GET', 'JSON');
}
function change_price(rec_id,goods_id){
var number = document.getElementById("goods_number_"+rec_id+"").value;
//alert(number);
Ajax.call('flow.php','step=update_group_cart&rec_id=' + rec_id +'&number=' + number+'&goods_id=' + goods_id, changePriceResp**e, 'GET', 'JSON');
}
function changePriceResp**e(result)
{
if(result.error == 1)
{
alert(result.content);
document.getElementById("goods_number_"+result.rec_id+"").value =result.number;
}
else
{
document.getElementById('subtotal_'+result.rec_id).innerHTML = result.subtotal;//商品总价
document.getElementById('cart_amount_desc').innerHTML = result.cart_amount_desc;//购物车商品总价说明
document.getElementById('market_amount_desc').innerHTML = result.market_amount_desc;//购物车商品总市价说明
}
}
</script>
接着把下一行的
<td align="right" bgcolor="#ffffff" >{$goods.subtotal}</td>
替换为
<td align="right" bgcolor="#ffffff" id="subtotal_{$goods.rec_id}">{$goods.subtotal}</td>
找到{$shopping_money}和{$market_price_desc},分别替换为<span id="cart_amount_desc">{$shopping_money}</span>
和
<span id="market_amount_desc">{$market_price_desc}</span>
//二次开发,ajax更新购物车
elseif($_REQUEST['step']=='update_group_cart')
{
include_once('includes/cls_json.php');
$result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '');
$json = new JSON;
$rec_id = $_GET['rec_id'];
$number = $_GET['number'];
$goods_id = $_GET['goods_id'];
$result['rec_id'] = $rec_id;
if ($GLOBALS['_CFG']['use_storage'] == 1)
{
$goods_number = $GLOBALS['db']->getOne("select goods_number from ".$GLOBALS['ecs']->table('goods')." where goods_id='$goods_id'");
if($number>$goods_number)
{
$result['error'] = '1';
$result['content'] ='对不起,您选择的数量超出库存您最多可购买'.$goods_number."件";
$result['number']=$goods_number;
die($json->encode($result));
}
}
$sql = "UPDATE " . $GLOBALS['ecs']->table('cart') . " SET goods_number = '$number' WHERE rec_id = $rec_id";
$GLOBALS['db']->query($sql);
/* 取得商品列表,计算合计 */
$cart_goods = get_cart_goods();
$subtotal = $GLOBALS['db']->getONE("select goods_price * goods_number AS subtotal from ".$GLOBALS['ecs']->table('cart')." where rec_id = $rec_id");
$result['subtotal'] = price_format($subtotal, false);
$result['cart_amount_desc'] = sprintf($_LANG['shopping_money'], $cart_goods['total']['goods_price']);
$result['market_amount_desc'] = sprintf($_LANG['than_market_price'], $cart_goods['total']['market_price'], $cart_goods['total']['saving'], $cart_goods['total']['save_rate']
);
die($json->encode($result));
}
- ECSHOP系统ajax更新购物车数量
- ECSHOP利用ajax更新购物车数量
- ajax更新购物车数量
- ajax更新购物车数量
- ecshop购物车页面使用ajax更新商品数量、小计、总价,点击加号和减号
- PHP 更新购物车数量
- magento -- 推荐插件 --Ajax更新购物车数量 --Ajax Shopping Cart Quantity Update
- Ecshop ajax 局部刷新购物车功能
- 怎么样给ECShop购物车添加购买数量加减按钮
- ecshop修改商品数量后自动更新购物车
- ecshop优化2-商品页购买数量加减按钮ecshop购物车页加减按钮
- ecshop购物车原理
- ecshop购物车原理
- Ecshop购物车原理
- [ecshop 资料 经过检验 推荐]ECSHOP自定义任意位置显示购物车免刷新显示数量的代码
- ECSHOP 商品详情页 购物车页 添加购买数量加减按
- ecshop购物车页面点击更新购物车按钮页面跳转
- 购物车数量提醒
- 手把手入门神经网络系列(1)_从初等数学的角度初探神经网络
- 使用org.apache.commons.fileupload上传文件
- 非负矩阵分解中基于L1和L2范式的稀疏性约束
- 初识ajax
- 自定义EL函数
- ECSHOP系统ajax更新购物车数量
- maya2016 API插件开发visual studio 2012的环境配置
- MAC 下配置adb环境
- javamail发送邮件
- 离职前的彷徨
- 读取Java文件到byte数组的三种方式
- GNU __attribute__分析
- 善用php-fpm的慢执行日志slow log分析PHP执行效率和程序BUG
- for_each调用类成员函数,mem_fun, mem_fun_ref用法