ECSHOP首页商品下面显示已销售量

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家

打开文件includes/lib_goods.php页后添加
  1. function get_buy_sum($goods_id){
  2. $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 表示确认了的订单才算
  3. return $GLOBALS['db']->getOne($sql);
  4. }
复制代码

在320行找到以下代码
  1. $goods[$idx]['brand_name']= isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : '';
复制代码

在下面添加
  1. $goods[$idx]['buy_num']= get_buy_sum($row['goods_id']);
复制代码

模板添加
  1. {if $goods.buy_num}
  2. {$goods.buy_num}
  3. {else}
  4. 0
  5. {/if}
复制代码


不懂的可以加交流群,免费交流解答。QQ群180035291

回答:

打开文件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);

}
复制代码
在320行找到以下代码
$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}
复制代码

功能挺好,研究一下。

恩,不错的功能

有很好的参考性