最模板 - 外贸网站建设,外贸网站模板

最模板

当前位置: 首页 > 建站教程 > CMS教程 > ECShop教程 >

ecshop列表调用评论数量和评论内容的方法

时间:2014-06-10 11:03来源: 作者: 点击:
ecshop 列表调用评论数量和评论内容,这个东西看起来比较新鲜。但是我们如果通过 ecshop 二次开发 , 对 ecshop 的相关功能进行调整的话,我们不但增强了 ecshop 商品页面的用户粘性,也能
(责任编辑:admin)

 

 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_valueparent_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();

 

------分隔线----------------------------
栏目列表
推荐内容