1. 程式人生 > >讓ecshop顯示商品銷量或者月銷量,呼叫評論數量

讓ecshop顯示商品銷量或者月銷量,呼叫評論數量

首先,ecshop的資訊顯示模組在../includes/lib_goods.php檔案

在其末尾新增下面這個函式

月銷量:(和總銷量二選一)

function ec_buysum($goods_id)

{

    $LMonth=strtotime("last month"); //前一個月

    $nowTime=time(); //當前時間

    $sql="select sum(goods_number) from " . $GLOBALS['ecs']->table('order_goods') . " AS g ,".$GLOBALS['ecs']->table('order_info') . " AS o WHERE o.order_id=g.order_id and g.goods_id = ".$goods_id." and o.pay_status=2 and o.add_time >= ".$LMonth." and o.add_time <= ".$nowTime." group by g.goods_id";

    if (($GLOBALS['db']->getOne($sql)) == ""){

            return "0";

        }else{

       return $GLOBALS['db']->getOne($sql);

    }

}

總銷量:(和月銷量二選一)

function ec_buysum($goods_id)

{

    $sql = "select sum(goods_number) from " . $GLOBALS['ecs']->table('order_goods') . " AS g ,".$GLOBALS['ecs']->table('order_info') . " AS o WHERE o.order_id=g.order_id and g.goods_id = " . $goods_id . " and o.order_status=5 " ;

    if (($GLOBALS['db']->getOne($sql)) == ""){

        return "0";

    }else{

           return $GLOBALS['db']->getOne($sql);

    }

}

然後,在上面的程式碼位置,大約是317行左右,找到

$goods[$idx]['brand_name'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : '';

在它的下面新增

$goods[$idx]['buy_num']= ec_buysum($row['goods_id']);

這樣,你在模版中使用

$goods.buy_num

就可以呼叫銷量資料了。

當然,這裡只是修改了首頁呼叫部分,在內頁,即商品詳情,你仍然只修改這個檔案

在大概594行的空白位置插入

/*顯示商品銷量*/

$row['buy_num']   = ec_buysum($row['goods_id']); 

 如果你想問,在分類頁如何操作呢?

分類頁與這個類似,分類頁檔名為

./category.php

在第508行下面插入

$row['buy_num']   = ec_buysum($row['goods_id']);

就可以了.

在模版中合適的位置使用

$goods.buy_num

來呼叫商品資料

**********************************************************************************

ecshop詳細頁呼叫評論數量


關於ecshop詳細頁呼叫評論數量,有部分使用者反映有瀏覽器相容問題。因此模板堂重新整理了另外一種解決方案:

 開啟includesb_insert.php 檔案,在最下面增加一個函式(注意別加在 “?>”外面 )/*** 呼叫評論資訊條數*/    function insert_comments_count($arr)    {    $count=$GLOBALS['db']->getOne('SELECT COUNT(*) FROM '.    $GLOBALS['ecs']->table('comment')."WHERE id_value='$arr[id]'".    "AND comment_type='$arr[type]' AND status = 1 AND parent_id = 0");    return $count;    }然後修改商品詳情模板檔案 themes/default/goods.dwt 在你想顯示商品評論數量的位置加入下面程式碼評論數:{insert name=comments_count type=$type id=$id}