您现在的位置是:首页 > 教程 > ecshop商城教程ecshop商城教程
ecshop实现ajax无刷新更新购物车的实例代码
卢帆新2023-11-14 20:34:30ecshop商城教程已有人查阅
导读先打开flow.dwt,找到,把下面的input框里面的替换成,然后在下一个后加一段js代码,找到{$shopping_money}和{$market_price_desc},分别替换为
先打开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″ 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.getElementByIdx_xx_x_x(“goods_number_”+rec_id+”").value++;
var number = document.getElementByIdx_xx_x_x(“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.getElementByIdx_xx_x_x(“goods_number_”+rec_id+”").value>1)
{
document.getElementByIdx_xx_x_x(“goods_number_”+rec_id+”").value–;
}
var number = document.getElementByIdx_xx_x_x(“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.getElementByIdx_xx_x_x(“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.getElementByIdx_xx_x_x(“goods_number_”+result.rec_id+”").value =result.number;
}
else
{
document.getElementByIdx_xx_x_x(‘subtotal_’+result.rec_id).innerHTML = result.subtotal;//商品总价
document.getElementByIdx_xx_x_x(‘cart_amount_desc’).innerHTML = result.cart_amount_desc;//购物车商品总价说明
document.getElementByIdx_xx_x_x(‘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>
然后打开flow.php,在elseif ($_REQUEST['step'] == ‘c**ignee’)上面加这一段代码。
//二次开发,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供货商插件ecshop供应商插件商家入住管理商品
ecshop模板屋原创多个ecshop供应商版本,最近多家同行盗用图片进行贩卖--请各位购买原创版本质量售后都有保障! -
ecshop中ajax的调用原理介绍
1、首先ecshop是如何定义ajax对象的。ecshop中的ajax对象是在js/transport.js文件中定义的。里面是ajax对象文件。声明了一个var Ajax = Transport;对象和一个方法Ajax.call = Transport.run; -
ecshop商品图片批量处理方法模糊的处理方法
很多人反映自己商城商品图片很模糊,其实和大家设置缩略图大小有关系,首先要看自己模板缩略图和商品详细页面CSS大小 是多少,然后在设置时间缩略图大小商店设置 -
ecshop底部帮助文章条数怎么改成显示10条
大家都知道ecshop底部的竖排帮助,是在后台文章分类,系统帮助里设置的, 行的分类名称就是后台系统帮助的分类,分类下的就是文章,但是ecshop默认的帮
留言与评论 (共有 条评论) |