首先,ecshop的信息显示模块在.
./includes/lib_goods.php文件
在其末尾添加下面这个函数

月销量:(和总销量二选一)

function ec_buysum($goods_id)
{ $LMonth=strtotime("last month"); //前一个月
$nowTime=time(); //当前时间
$sql="select sum(goods_number) from " . $GLOBALS['ecs']->table('order_goods') . " AS g ,".$GLOBALS['ecs']->table('order_info') . " AS o WHERE o.order_id=g.order_id and g.goods_id = ".$goods_id." and o.pay_status=2 and o.add_time >= ".$LMonth." and o.add_time <= ".$nowTime." group by g.goods_id"; if (($GLOBALS['db']->getOne($sql)) == ""){
return "0";
}else{
return $GLOBALS['db']->getOne($sql);
} }

总销量:(和月销量二选一)

function ec_buysum($goods_id)
{
$sql = "select sum(goods_number) from " . $GLOBALS['ecs']->table('order_goods') . " AS g ,".$GLOBALS['ecs']->table('order_info') . " AS o WHERE o.order_id=g.order_id and g.goods_id = " . $goods_id . " and o.order_status=5 " ;
if (($GLOBALS['db']->getOne($sql)) == ""){
return "0";
}else{
return $GLOBALS['db']->getOne($sql);
}
}

然后,在上面的代码位置,大约是317行左右,找到

$goods[$idx]['brand_name'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : '';

在它的下面添加

$goods[$idx]['buy_num']= ec_buysum($row['goods_id']);

这样,你在模版中使用

$goods.buy_num

就可以调用销量数据了.

当然,这里只是修改了首页调用部分,在内页,即商品详情,你仍然只修改这个文件

在大概594行的空白位置插入

        /*显示商品销量*/
$row['buy_num'] = ec_buysum($row['goods_id']);

如果你想问,在分类页如何操作呢?

分类页与这个类似,分类页文件名为

./category.php

在第508行下面插入

$row['buy_num']   = ec_buysum($row['goods_id']);

就可以了.

在模版中合适的位置使用

$goods.buy_num

来调用商品数据

05-07 11:17