大家都知道ECSHOP首頁的推薦、熱賣和新品三個(gè)板塊的商品都是從所有商品里讀取出來的。如果我想“在ecshop首頁調(diào)用指定分類的推薦、熱賣和新品?”該怎么辦呢,下面教你一種方法:
找到ecshop的includes/lib_goods.php,
把SQL語句改一下,與category表關(guān)聯(lián)即可
將
$sql = 'SELECT g.goods_id,g.goods_name, g.goods_name_style,
g.market_price, g.shop_price AS org_price, g.promote_price, ' .
修改為
$sql = 'SELECT g.goods_id,g.cat_id,c.parent_id,g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' .
繼續(xù)找到
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' .
在它下面加一句
'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON c.cat_id = g.cat_id ' .
然后將
if (!empty($cats))
{
$sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) .")";
}
改為
if (!empty($cats))
{
$sql .= " AND (c.parent_id =" . $cats. " OR " . get_extension_goods($cats) .")";
}
這個(gè)是和分類表建立關(guān)聯(lián),調(diào)出商品所在分類的上級分類
然后在index.php中增加下面代碼
$smarty->assign('chot_goods_35', get_category_recommend_goods('hot','35')); //指定分類下的熱銷商品
注意這個(gè)35是一級分類的ID,然后在模板中調(diào)用即可
<!--{foreach from=$chot_goods_35 item=goods}-->
<div style="padding-top: 8px;" class="new-tr">
<a target="_blank" href="{$goods.url}"><img width="116" height="130" border="0" alt="{$goods.name|escape:html}" src="{$goods.thumb}"></a>
<div>
<a target="_blank" href="{$goods.url}">{$goods.name|escape:html}</a><br>
<span style="color: rgb(102, 102, 102); text-decoration: line-through;">市場價(jià):{$goods.market_price}</span><br>
特賣價(jià):<span style="color: rgb(255, 0, 0);">{$goods.shop_price}</span><br>
<span class="font-gmm"><a href="javascript:addToCart({$goods.id})">立即搶購</a></span>
</div>
<span class="new-line"></span>
</div>
<!--{/foreach}-->
同理,新品,推薦都可以調(diào),只要把hot改為new 或者best就可以了
更多信息請查看IT技術(shù)專欄