1. 程式人生 > >在ECSHOP首頁每個商品下顯示已銷售量

在ECSHOP首頁每個商品下顯示已銷售量

問題:想在首頁每個商品下顯示“已銷售XX個”,該如何操作呢?

教程:
第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']);

最後就是通過在模板檔案中呼叫了,如下這般呼叫

{if $goods.buy_num}
{$goods.buy_num}
{else}
0
{/if}