1、在首页新品、热卖、精品等调用商品销售
打开 includes/lib_goods.php
在文件尾部?>前添加以下代码:function get_buy_sum($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=1 " ;//o.order_status=1 表示确认了的订单才算
return $GLOBALS['db']->getOne($sql);
}
再查找:$goods[$idx]['brand_name'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : '';
约 317行
在下面添加以下代码:$goods[$idx]['buy_num']= get_buy_sum($row['goods_id']);
然后在前台相关模板文件中使用以下代码调用:{if $goods.buy_num}
{$goods.buy_num}
{else}
0
{/if}
2、在分类页列表调用销量
打开 category.php
查找:$arr[$row['goods_id']]['type'] = $row['goods_type'];
在下面增加:$arr[$row['goods_id']]['buy_num'] = get_buy_sum($row['goods_id']);//销量
然后在 goods_list.lbi 中使用以下代码调用{if $goods.buy_num}
{$goods.buy_num}
{else}
0
{/if}
3、在商品详情页中调用销量
打开 includes/lib_goods.php
查找:$row['goods_thumb'] = get_image_path($goods_id, $row['goods_thumb'], true);
在下面添加:$row['buy_num'] = get_buy_sum($row['goods_id']);
然后在 goods.dwt 中调用{if $goods.buy_num}{$goods.buy_num}{else}0{/if}件