ecshop首页和分类页调用商品货号的解决办法

2016-09-07 22:03 来源:www.chinab4c.com 作者:ecshop专家

找到网站根目录下面的includes目录,打开之后找到lib_goods.php文件,打开之后找到

/**
* 获得推荐商品
*
* @access public
* @param string $type 推荐类型,可以是 best, new, hot, promote
* @return array
*/
function get_recommend_goods($type = '', $cats = '')
{
if (!in_array($type, array('best', 'new', 'hot', 'promote')))
{
return array();
}

$time = gmtime();

$order_type = 0;

/* 取得每一项的数量限制 */
$type2lib = array('best'=>'recommend_best', 'new'=>'recommend_new', 'hot'=>'recommend_hot', 'promote'=>'recommend_promotion');
$num = get_library_number($type2lib[$type]);

$sql = 'SELECT g.goods_id, g.goods_name, 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 ';


1。上面这段代码,在在goods_id 后添加 goods_sn,改后如下

$sql = 'SELECT g.goods_id, g.goods_sn, g.goods_name, 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 ';


2.在后面不远处 添加代码$goods[$idx]['goods_sn']     = $row['goods_sn'];,改后如下


$goods[$idx]['id']           = $row['goods_id'];
        $goods[$idx]['name']         = $row['goods_name'];
        $goods[$idx]['brief']        = $row['goods_brief'];
  $goods[$idx]['goods_sn']     = $row['goods_sn'];
        $goods[$idx]['brand_name']   = $row['brand_name'];
        $goods[$idx]['goods_style_name']   = add_style($row['goods_name'],$row['goods_name_style']);


3.接下来在你使用的风格的library中,修改recommend_best.lbi,增加{$goods.goods_sn}在需要显示位置就可以了。recommend_new.lbi,recommend_hot.lbi都是一样。

4.分类页的解决办法。其实跟上面的一样,大家先到根目录下找到category.php,打开找到
 

function category_get_goods($children, $brand, $min, $max, $ext, $size, $page, $sort, $order)
{
    $display = $GLOBALS['display'];
    $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ".
            "g.is_delete = 0 AND ($children OR " . get_extension_goods($children) . ')';

    if ($brand > 0)
    {
        $where .=  "AND g.brand_id=$brand ";
    }

    if ($min > 0)
    {
        $where .= " AND g.shop_price >= $min ";
    }

    if ($max > 0)
    {
        $where .= " AND g.shop_price <= $max ";
    }

    /* 获得商品列表 */
    $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]' " .
            "WHERE $where $ext ORDER BY $sort $order";


在g.goods_id字段后面增加g.goods_sn,同时在下面不远处跟上面的相似,增加$arr[$row['goods_id']]['goods_sn']      = $row['goods_sn'];程序部分修改了,接下来大家自己去修改相应风格的模板,增加{$goods.goods_sn}在需要显示位置就可以了。

 

搜索页是一样的道理,只要修改search.dwt和search.php即可

(责任编辑:chinab4c)