© 2002-2018 最模板 zuimoban.com 版权所有,并保留所有权利。
ecshop模板网,专注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 . " 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']] : ''; |
$goods[$idx]['buy_num']= get_buy_sum($row['goods_id']); |
最后就是通过在模板文件中调用了,如下这般调用
{if $goods.buy_num} {$goods.buy_num} {else} 0 {/if} |