ecshop列表调用评论数量和评论内容
2012-03-08 22:11 来源:www.chinab4c.com 作者:ecshop专家
ecshop列表调用评论数量和评论内容,这个东西看起来比较新鲜。但是我们如果通过ecshop二次开发,对ecshop的相关功能进行调整的话,我们不但增强了ecshop商品页面的用户粘性,也能将ecshop商品列表页面处理的更加灵活。
首先我们知道ecshop评论功能,其实就是建立在comment表和goods两个ecshop数据库表上面的。而comment表中的id_value对应着goods表中的goods_id字段。这样的话就通过这两个值将两个表中间的关系建立起来了。、
以下是相关的函数调用。
function my_promote_goods($cats = '')
{
global $db;
global $ecs;
$time = gmtime();
/* 取得促销lbi的数量限制 */
$sql = 'SELECT g.goods_id, g.goods_name, g.seller_note, g.goods_number, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
"promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, " .
"g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' .
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
"WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 " .
" ";
$sql .= " ORDER BY g.sort_order, g.last_update DESC ";
$sql .= " LIMIT 100 ";
$result = $GLOBALS['db']->getAll($sql);
$goods = array();
foreach ($result AS $idx => $row)
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
}
else
{
$goods[$idx]['promote_price'] = '';
}
$goods[$idx]['id'] = $row['goods_id'];
$goods[$idx]['ccount'] = $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' .$GLOBALS['ecs']->table('comment').
" WHERE id_value = '".$row['goods_id']."' AND comment_type = '0' AND status = 1 AND parent_id = 0");
$sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('comment') ." WHERE id_value = '".$row['goods_id']."' AND comment_type = '0' AND status = 1 AND parent_id = 0".' ORDER BY comment_id DESC limit 3';
$list = array();
$r = $db->getAll($sql);
if($r){
foreach($r as $kkk => $vvv){
$list[$kkk]['username'] = $vvv['username'];
$list[$kkk]['addtime'] = local_date("Y-m-d H:i:s",$vvv['addtime']);
$list[$kkk]['content'] = sub_str($vvv['content'],20,false);
}
}
$goods[$idx]['list'] = $list;
$goods[$idx]['name'] = $row['goods_name'];
$goods[$idx]['seller_note'] = $row['seller_note'];
$goods[$idx]['num'] = $row['goods_number'];
$goods[$idx]['percent'] = round( ($row['shop_price'] - $row['promote_price'])/ $row['shop_price'] * 100 , 0) . "%";
$goods[$idx]['brief'] = $row['goods_brief'];
$goods[$idx]['brand_name'] = $row['brand_name'];
$goods[$idx]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']);
$goods[$idx]['market_price'] = price_format($row['market_price']);
$goods[$idx]['shop_price'] = price_format($row['shop_price']);
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
/* 促销时间倒计时 */
$time = gmtime();
if ($time >= $row['promote_start_date'] && $time <= $row['promote_end_date'])
{
$goods[$idx]['gmt_end_time'] = local_date('M d, Y H:i:s',$row['promote_end_date']);
}
else
{
$goods[$idx]['gmt_end_time'] = 0;
}
}
return $goods;
}
这里面有2个地方要注意。
1:第一个是通过id_value和parent_id来取得该商品下面评论条数.
$goods[$idx]['ccount'] = $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' .$GLOBALS['ecs']->table('comment').
" WHERE id_value = '".$row['goods_id']."' AND comment_type = '0' AND status = 1 AND parent_id = 0");
2:通过goods_id来关联出该商品ID下前三条ecshop评论内容。
$sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('comment') ." WHERE id_value = '".$row['goods_id']."' AND comment_type = '0' AND status = 1 AND parent_id = 0".' ORDER BY comment_id DESC limit 3';
$list = array();
最近更新
常用插件
- ecshop降价通知登记插件
ecshop降价通知登记插件,主要是为了方便某些客户,对商品价格要求比...
- ecshop红包修改成满多少减
我们在长期使用ecshop的时候,我们可以发现。ecshop的红包是一个非常强...
- ecshop购物车功能改进[插件
ecshop购物车功能改进[插件套餐]主要是我们最近开发工作和开发项目中。...
- ecshop通用红包编码
很多时候,为了结合促销,必须扩展一下ecshop的红包功能。ecshop的红包...
- ecshop分类树中统计商品数
最近忙于开发其他项目,在不少朋友不断要求和催促的情况下,做出了该小...