問題:想在首頁每個(gè)商品下顯示“已銷售XX個(gè)”,該如何操作呢?
教程:
第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 ;
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']= get_buy_sum($row['goods_id']);
最后就是通過在模板文件中調(diào)用了,如下這般調(diào)用
{if $goods.buy_num}
{$goods.buy_num}
{else}
0
{/if}
掃描二維碼手機(jī)查看該文章
文章引用:http://www.qingbaosc.com/news/webzhishi/155.html




