我们想让ECshop的分类数后面显示该分类产品具体数量,这里我提供具体办法:

修改includes/lib_goods.php

$sql = ‘SELECT cat_id,cat_name ,parent_id,is_show ‘ .
‘FROM ‘ . $GLOBALS[‘ecs’]->table(‘category’) .
“WHERE parent_id = ‘$parent_id’ AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC”;
$res = $GLOBALS[‘db’]->getAll($sql);
的下面增加

$sql = “SELECT cat_id, COUNT(*) AS goods_num ” .
” FROM ” . $GLOBALS[‘ecs’]->table(‘goods’) . ” AS g ” .
” GROUP BY cat_id”;

$res2 = $GLOBALS[‘db’]->getAll($sql);
$newres = array();
foreach($res2 AS $row)
{
$newres[$row[‘cat_id’]] = $row[‘goods_num’];
}

2.cat_arr[$row[‘cat_id’]][‘id’]   = $row[‘cat_id’];
下面增加
$cat_arr[$row[‘cat_id’]][‘num’] = !empty($newres[$row[‘cat_id’]]) ? $newres[$row[‘cat_id’]] : 0;

2.修改category_tree.lib库,写入num变量。

<dt><a href=”{$cat.url}”>{$cat.name|escape:html}</a>({$cat.num})</dt>

效果如下:

ecshop分类树显示具体商品数量
ECshop分类树显示具体分类商品数量。