ECSHOP商品列表调用评论数量实现方法
发布:smiling 来源: PHP粉丝网 添加日期:2015-04-04 10:52:44 浏览: 评论:0
ECSHOP商品列表在系统默认状态下时无法调用它们的评论及评论数量了,因为一个客户有这种要求,下面就整理了一篇ECSHOP商品列表调用评论数量实现方法与大家一起分享.
ECSHOP的商品列表页如果能显示相对应的评论数,那就更好了,我们也可以添加一些浏览次数,这样商品的列表看起来就更加丰富了,今天我们就给大家来讲解一下如何在ECSHOP的商品列表调用评论数量,需要修改系统文件,修改之前请备份相关文件.
修改分类文件,修改category.php 文件,定位到 category_get_goods() 函数部分找到如下代码:
- $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .
- "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
- 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
- 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
- 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' .
- "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .//开源软件:phpfensi.com
- "WHERE $where $ext ORDER BY $sort $order";
- //修改为
- $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .
- "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
- " IFNULL(AVG(r.comment_rank),0) AS comment_rank,IF(r.comment_rank,count(*),0) AS comment_count, ".
- 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
- 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
- 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' .
- "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
- ' LEFT JOIN '. $GLOBALS['ecs']->table('comment') .' AS r '.
- 'ON r.id_value = g.goods_id AND comment_type = 0 AND r.parent_id = 0 AND r.status = 1 ' .
- "WHERE $where $ext group by g.goods_id ORDER BY $sort $order";
- //然后继续找到
- $arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
- //在它下面增加几行代码
- $row['comment_rank'] = ceil($row['comment_rank']) == 0 ? 5 : ceil($row['comment_rank']);
- $arr[$row['goods_id']]['comment_rank']=$row['comment_rank'];
- $arr[$row['goods_id']]['comment_count']=$row['comment_count'];
修改模版文件:修改 themes/default/library/goods_list.lbi文件找到如下代码:
<a href="javascript:collect({$goods.goods_id});" class="f6">{$lang.btn_collect}</a>
在它上面增加:
<img src="images/stars{$goods.comment_rank}.gif" style="width:78px;height:15px;" /><br>
评论数:{$goods.comment_count}<br>
PS:大家都知道ECSHOP系统有缓存机制,如果某个商品有了新的评论,列表页的评论数量不会立马随着更新,得等到下次更新缓存的时候才会更新.
如果您想列表页能即时体现评论数量的变化,只需继续进行下面修改即可,把 category.php 文件的如下代码:
$smarty->caching = true;
修改为:$smarty->caching = false;
Tags: ECSHOP商品列表 ECSHOP评论数量
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)