首页 > 网站 > 建站经验 > 正文

在ECSHOP首页每个商品下显示已销售量

2024-04-25 20:32:18
字体:
来源:转载
供稿:网友

第1步:打开文件 includes/lib_goods.php

在该文件的末尾添加如下代码片段

[html] view plaincopy

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行左右, 找到

[html] view plaincopy

$goods[$idx]['brand_name'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : '';

在它下面添加

[html] view plaincopy

$goods[$idx]['buy_num']= get_buy_sum($row['goods_id']);

最后就是通过在模板文件中调用了,如下这般调用

[html] view plaincopy

{if $goods.buy_num}

{$goods.buy_num}

{else}

0

{/if}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表