首页 » 二次开发 » 阅读文章
为ecshop添加商品数量优惠方案
购买数量达到优惠数量时享受的优惠价格;下面的功能是购物车总金额达到一定、商品款数达到一定或者某商品数量达到一定,那么就享受购物车里所有商品优惠价格;
在购物车文件里加上下面的函数,分别在加入、更新、删除购物车里加上函数名;
/*
*达到多少件商品优惠价格
*
*/
function mywe(){
$max=500; //达到该金额就可以优惠
$kss=4; //达到该商品款数就可以优惠
$num=2; //以该数量的优惠价格
//目前最大金额
$sql=”select sum(goods_price) from “.$GLOBALS[‘ecs’]->table(‘cart’).” where session_id='” . SESS_ID . “‘”;
$m = $GLOBALS[‘db’]->getone($sql);
$sql=”select goods_id,goods_price from “.$GLOBALS[‘ecs’]->table(‘cart’).” as c where goods_id in (select goods_id from “.$GLOBALS[‘ecs’]->table(‘cart’).” where c.goods_id=goods_id) and session_id='” . SESS_ID . “‘”;
$gids=$GLOBALS[‘db’]->getAll($sql);
$ks=count($gids);//购物车的商品款数
//echo($ks.'<br>’);print_r($gids);exit;
if($ks>0){
foreach($gids as $value){
$goods_price1=0;
if($ks>=$kss || $m>=$max){
$goods_price1 = get_final_price($value[‘goods_id’], $num, true);
}
$sql=”select sum(goods_number) as num from “.$GLOBALS[‘ecs’]->table(‘cart’).” where goods_id='”.$value[‘goods_id’].”‘ and session_id='” . SESS_ID . “‘ group by goods_id”;
$nums = $GLOBALS[‘db’]->getone($sql);
$goods_price2 = get_final_price($value[‘goods_id’], $nums, true);
if($goods_price1>=$goods_price2 || $goods_price1==0){
$goods_price=$goods_price2;
}else{
$goods_price=$goods_price1;
}
if($goods_price!=$value[‘goods_price’]){
$sql = “UPDATE “.$GLOBALS[‘ecs’]->table(‘cart’).” SET goods_price = ‘$goods_price’ WHERE goods_id='”.$value[‘goods_id’].”‘ AND session_id='” . SESS_ID . “‘;”;
$GLOBALS[‘db’]->query($sql);
}
}
}
}
大家有什么好的方案请多多提点!
评论 共1条 (RSS 2.0) 发表评论
空间不错,进来学习一下