ecshop2.7.0商品分类显示数量
发布:smiling 来源: PHP粉丝网 添加日期:2013-11-15 21:38:40 浏览: 评论:0
1,修改includes/lib_goods.php,改写下两个函数。
- function get_categories_tree($cat_id = 0)
- {
- if ($cat_id > 0)
- {
- $sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$cat_id'";
- $parent_id = $GLOBALS['db']->getOne($sql);
- }
- else
- {
- $parent_id = 0;
- }
- $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id' AND is_show = 1 ";
- if ($GLOBALS['db']->getOne($sql) || $parent_id == 0)
- {
- $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'];
- }
- foreach ($res AS $row)
- {
- if ($row['is_show'])
- {
- $cat_arr[$row['cat_id']]['id'] = $row['cat_id'];
- $cat_arr[$row['cat_id']]['num'] = !emptyempty($newres[$row['cat_id']]) ? $newres[$row['cat_id']] : 0;
- $cat_arr[$row['cat_id']]['name'] = $row['cat_name'];
- $cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
- if (isset($row['cat_id']) != NULL)
- {
- $cat_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);
- }
- }
- }
- }
- if(isset($cat_arr))
- {
- return $cat_arr;
- }
- }
- function get_child_tree($tree_id = 0)
- {
- $three_arr = array();
- $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$tree_id' AND is_show = 1 ";
- if ($GLOBALS['db']->getOne($sql) || $tree_id == 0)
- {
- $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
- 'FROM ' . $GLOBALS['ecs']->table('category') .
- "WHERE parent_id = '$tree_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
- $res = $GLOBALS['db']->getAll($child_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'];
- }
- foreach ($res AS $row)
- {
- if ($row['is_show'])
- $three_arr[$row['cat_id']]['num'] = !emptyempty($newres[$row['cat_id']]) ? $newres[$row['cat_id']] : 0;
- $three_arr[$row['cat_id']]['id'] = $row['cat_id'];
- $three_arr[$row['cat_id']]['name'] = $row['cat_name'];
- $three_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
- if (isset($row['cat_id']) != NULL)
- {
- $three_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);
- }
- }
- }
- return $three_arr;
- }
2.修改category_tree.lib库,写入num变量。
- < div class="box">
- < div class="box_1">
- < div id="category_tree">
- < !--{foreach from=$categories item=cat}-->
- < dl>
- < dt>{$cat.name|escape:html}({$cat.num})
- < !--{foreach from=$cat.cat_id item=child}-->
- < dd>{$child.name|escape:html}({$child.num})
- < !--{foreach from=$child.cat_id item=childer}-->
- < dd> {$childer.name|escape:html}({$childer.num})
- < !--{/foreach}-->
- < !--{/foreach}-->
- < !--{/foreach}-->
- < /div>
- < /div>
Tags: ecshop2 7 0 商品分类 显示
相关文章
- ·将ECSHOP2.7.3后台左侧菜单中的云服务中心删除掉(2014-06-19)
- ·删除ECSHOP2.7.3后台左侧菜单中的云服务中心(2014-07-17)
- ·使用.htaccess来实现ecshop 301重定向的方法(伪静态可行)(2013-11-15)
- ·Ecshop网店 301重定向(2014-06-19)
- ·ecshop iis虚拟主机301重定向以及url重写代码(2014-06-19)
- ·ECSHOP 301重新定向(2014-06-20)
- ·去掉ECSHOP商品评论的30秒时间限制(2014-07-08)
- ·ecshop运行超过30秒超时的限制解决办法(2014-07-08)
- ·ecshop加404页面(2014-11-18)
- ·Ecshop商品分类页面,如何在价格后面添加商品点击数?(2014-11-18)
- ·让ECshop分类页的商品分类树与首页的商品分类树一样(2015-09-28)
- ·ecshop分类树显示所有分类的解决方法(2013-12-02)
- ·让ECSHOP其他页面也能显示友情链接(2014-06-14)
- ·ECSHOP广告位添加之后不显示的原因分析(2014-06-14)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)