欢迎来到天天文库
浏览记录
ID:20306251
大小:45.00 KB
页数:3页
时间:2018-10-08
《ecshop分类树显示分类下商品数量》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Ecshop分类树显示分类下的商品数量ECSHOP开发中心(68ecshop.com)第一步:修改includes/lib_goods.php找到functionget_categories_tree($cat_id=0)方法找到下面代码/*获取当前分类及其子分类*/ $sql='SELECTcat_id,cat_name,parent_id,is_show'. 'FROM'.$GLOBALS['ecs']->table('category'). "WHEREparent_id='$parent_id'ANDis_show=1ORDERBYso
2、rt_orderASC,cat_idASC"; $res=$GLOBALS['db']->getAll($sql);在这段代码下新增$sql="SELECTcat_id,COUNT(*)ASgoods_num". "FROM".$GLOBALS['ecs']->table('goods')."ASg". "GROUPBYcat_id"; $res2=$GLOBALS['db']->getAll($sql); $newres=array(); foreach($res2AS$row) { $newres[$row['cat_id']]=$row['goods
3、_num']; }第二步:在该方法中找到$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;第三步:找到functionget_child_tree($tree_id=0)方法在该方法中的 $child_sql='SELECTcat_id,cat_name,parent_id,is_show'. 'FROM'.$GLOBALS[
4、'ecs']->table('category'). "WHEREparent_id='$tree_id'ANDis_show=1ORDERBYsort_orderASC,cat_idASC"; $res=$GLOBALS['db']->getAll($child_sql);代码下增加 $sql="SELECTcat_id,COUNT(*)ASgoods_num". "FROM".$GLOBALS['ecs']->table('goods')."ASg". "GROUPBYcat_id"; $res2=$GLOBALS['db']->getAll($s
5、ql); $newres=array(); foreach($res2AS$row) { $newres[$row['cat_id']]=$row['goods_num']; }第四步:在该方法中的$three_arr[$row['cat_id']]['url'] =build_uri('category',array('cid'=>$row['cat_id']),$row['cat_name']);代码下增加$three_arr[$row['cat_id']]['num'] =!empty($newres[$row['cat_id']])?$newres[$row
6、['cat_id']]:0;第五步:修改category_tree.lib库,写入num变量。
7、escape:html}({$cat.num})
8、escape:html}({$child.num})
10、escape:html}({$childer.num})
此文档下载收益归作者所有