php,,
``,,这段代码会输出商品的收藏数量。请确保将此代码添加到适当的位置,以便在商品详情页上正确显示收藏数量。在ECSHOP中显示商品详情页的收藏数量,可以通过修改后端数据库查询语句和前端模板文件来实现,下面将详细介绍实现这一功能的步骤:
修改后端数据库查询语句
1、打开/includes/lib_insert.php
文件:
在文件末尾添加以下代码:
```php
function insert_goods_collect($arr) {
$sql = 'select count(user_id) as ids from ' . $GLOBALS['ecs']->table('collect_goods') . " as co where co.goods_id=" . $arr['goods_id'];
$row = $GLOBALS['db']->GetRow($sql);
if ($row) {
$ids = intval($row['ids']);
} else {
$ids = 0;
}
return $ids;
}
```
修改前端模板文件
2、打开模板文件/themes/default/goods.dwt
:
在需要显示收藏数量的位置添加以下代码:
```html
<strong>收藏人气:</strong>{insert name='goods_collect' goods_id=$id}人<br>
```
相关问题与解答
问题一:如何在用户中心首页显示用户的收藏商品总数?
答:可以在/includes/lib_clips.php
文件中增加以下代码来获取用户的商品收藏总数:
//获取用户商品收藏数 $collect_sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('collect_goods') . " WHERE user_id = '" . $user_id . "'"; $info['collect_count'] = $GLOBALS['db']->getOne($collect_sql);
然后在/themes/default/user_clips.dwt
文件中添加以下代码来显示收藏总数:
<br />您共收藏了<b>{$info.collect_count}</b>个商品,现在去<a href="user.php?act=collection_list">查看</a>
问题二:如何在商品详情页显示已售商品数量和评论数量?
答:首先在goods.php
页面最下面加入两个函数get_buy_sum
和get_comment_num
,然后在goods.php
中调用这两个函数并将结果赋值给 Smarty 变量,最后在goods.dwt
模板中添加相应的显示代码:
function get_buy_sum($goods_id) { $sql = 'SELECT IFNULL(SUM(g.goods_number), 0) ' . 'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' . 'FROM ' . $GLOBALS['ecs']->table('order_goods') . ' AS g ' . "WHERE o.order_id = g.order_id " . "AND o.order_status = '" . OS_CONFIRMED . "' " . "AND o.shipping_status " . db_create_in(array(SS_SHIPPED, SS_RECEIVED)) . " AND o.pay_status " . db_create_in(array(PS_PAYED, PS_PAYING)) . " AND g.goods_id = '$goods_id'"; return $GLOBALS['db']->getOne($sql); } function get_comment_num($goods_id) { $sql = "select count(*) from " . $GLOBALS['ecs']->table('comment') . " where id_value='" . $goods_id . "' AND status = 1"; return $GLOBALS['db']->getOne($sql); }
在goods.php
中加入:
$smarty->assign('buy_num', get_buy_sum($goods_id)); $smarty->assign('comment_num', get_comment_num($goods_id));
在goods.dwt
模板中加:
<!-{if $buy_num} --> <li class="clearfix"> <dd> <strong>累计售出:</strong>{$buy_num} </dd> </li> <!-{/if} --> <!-{if $comment_num} --> <li class="clearfix"> <dd> <strong>评论数量:</strong><a href="#comment">{$comment_num}</a> </dd> </li> <!-{/if} -->