ecshop 下分类树显示商品的数量(二次开发)

修改includes/lib_goods.php1.在sql语句
$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;3.修改category_tree.lib库,写入num变量。<dt><a href=”{$cat.url}”>{$cat.name|escape:html}</a>({$cat.num})</dt>
这样就可以搞定了!!
经验是由痛苦中粹取出来的

ecshop 下分类树显示商品的数量(二次开发)

相关文章:

你感兴趣的文章:

标签云: