ecshop2.7增购买数量限制功能
2009-10-20 17:46 来源:www.chinab4c.com 作者:ecshop专家
ecshop电子商务系统中,为了方便管理,方便b4c服务的促销,我们可以对某个产品,在特定的b4c环境下,拿出来做促销。ecshop2.7中控制购买数量功能的实现也非常容易。
1:首先。在表goods中增加gc字段,控制该商品购买数量。
alter table ecs_goods add column gc int(1) default 0;后台 -》 数据库管理 -》 数据库查询。在里面执行上面语句
2:修改admin/goods_info.htm
<tr>
<td class="label">
控制购买数量:
</td>
<td><input type="text" name="gc" value="{$goods.gc}" size="2" /></td>
</tr>
3:修改admin/goods.php
增加$gc = empty($_POST['gc']) ? '0' : intval($_POST['gc']);.取得gc控制数量数据,$sql语句中增加'$gc'插入字段。update语句中增加"gc = '$gc', ".修改字段
4:js/common.js函数addToCartResponse()中增加以下内容。
//控制购买数量的JS
else if(result.error==22){
alert(result.message);
}
else if(result.error==23){
alert(result.message);
location.href = 'user.php';
}
5:flow.php中的$_REQUEST['step'] == 'add_to_cart'中增加以下控制代码
//处理购买时候数量的控制.
$gc = $db -> getOne("select gc from ".$ecs->table('goods')." where goods_id = ".$goods-> goods_id);//如果限制了数量
if($gc){
if(!$_SESSION[user_id]){//登陆购买
$result['message'] = '购买该产品,你需要登陆';
$result['error'] = 23;
$result['goods_id'] = stripslashes($goods->goods_id);
die($json->encode($result));
}
$co = $db -> getOne("select sum(og.goods_number) from ".$ecs->table('order_goods')." og, ".$ecs->table('order_info')." o where og.goods_id = ".$goods->goods_id." and o.user_id = ".$_SESSION[user_id]." and o.order_id = og.order_id");
if($co){
$gcl = $gc - $co;
if($gcl == 0){
$result['message'] = '您已经购买过'.$gc."件产品,不能再次购买该产品";
$result['error'] = 22;
$result['goods_id'] = stripslashes($goods->goods_id);
die($json->encode($result));
}
if($goods->number > $gcl){
$result['message'] = '您已经购买过该产品,您还可以购买'.$gcl."件";
$result['error'] = 22;
$result['goods_id'] = stripslashes($goods->goods_id);
die($json->encode($result));
}
}
if($goods->number > $gc){
$result['message'] = '该产品您只能购买'.$gc."件";
$result['error'] = 22;
$result['goods_id'] = stripslashes($goods->goods_id);
die($json->encode($result));
}
}
//控制购买数量结束
6:flow.php的flow_update_cart()函数中。增加以下代码
//购买数量控制和检测
$gc = $db -> getOne("select gc from ".$ecs->table('goods')." where goods_id = ".$goods['goods_id']);//如果限制了数量
if($gc){
$co = $db -> getOne("select sum(og.goods_number) from ".$ecs->table('order_goods')." og, ".$ecs->table('order_info')." o where og.goods_id=".$goods['goods_id']." and o.user_id = ".$_SESSION[user_id]." and o.order_id = og.order_id");
if($co){
$gc1 = $gc - $co;
if($val > $gcl){
show_message("您已经购买过{$row[goods_name]}{$co}件,你只能再购买该产品{$gc1}件");
exit;
}
}
if( $val > $gc){
show_message("你只能购买产品{$row[goods_name]}{$gc}件");
exit;
}
}
//购买数量控制和检测
来源:中国B4C电子商务
最近更新
常用插件
- ecshop文章实现分类扩展插
插件介绍:ecshop文章分类扩展插件,主要是模仿ecshop商品扩展,他可以属...
- ecshop提货单插件
ecshop提货单插件,是我们在ecshop二次开发中,根据客户实际需要,通过...
- ecshop二次开发打印采购单
在ecshop电子商务系统的开发和使用过程中,我们常常要统计订单的信息...
- Ecshop二次开发积分兑换现
Ecshop 二次开发积分兑换现金的功能 , 系统可以在后台开起积分兑换现金...
- ecshop 二次开发报价单分页
ecshop 二次开发报价单分页/购买插件...



