第一步:在/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 WHEREo.order_status >1 ando.order_id=g.order_id and g.goods_id = " . $goods_id ;/*注意订单状态*/
return $GLOBALS['db']->getOne($sql);
}
首页精品、新品、热销版块显示“累计售出”:
在$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']);/*首页调用已售出件数*/
首页分类产品版块显示“累计售出”(这块注意找准位置"获得指定分类下的商品"):
在$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
下添加:$goods[$idx]['buy_num']= get_buy_sum($row['goods_id']);/*首页分类下的产品调用已售出件数*/
程序部分就OK了,然后将其调用模板显示:
...best/hot/new.lbi and cat_goods.lbi 中添加如下:
<span>已售出:
{if $goods.buy_num}
<font style="color:#ceaa1f;font-weight:bold;">{$goods.buy_num}</font>
{else}
<font style="color:#ceaa1f;font-weight:bold;">0</font>
{/if}件</span>