小編給大家介紹在日常中如何使用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即可
希望本文所述對大家設計有所幫助
新聞熱點
疑難解答