ecshop 调用指定分类的推荐,热卖,新品

时间:2023-03-08 18:34:40

未测试

1、includes/lib_goods.php文件。把SQL语句改一下,与category表关联即可

$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, ' .

2、找到

'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 ' .

3、将

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) .")";
}

上面是和分类表建立关联,调出商品所在分类的上级分类

4、在index.php中增加下面代码

$smarty->assign('chot_goods_35',   get_category_recommend_goods('hot','35'));     //指定分类下的热销商品
注意上面这个35是一级分类的ID,然后在index.dwt模板中调用即可
<!--{foreach from=$chot_goods_35 item=goods}-->
<div>
<a href="{$goods.url}"><img width="116" height="130" border="0" alt="{$goods.name|escape:html}" src="{$goods.thumb}"></a>
<div>
<a href="{$goods.url}">{$goods.name|escape:html}</a>
<span>市场价:{$goods.market_price}</span>
特卖价:<span>{$goods.shop_price}</span>
<span><a href="javascript:addToCart({$goods.id})">立即抢购</a></span>
</div>
</div>
<!--{/foreach}-->

同理其它新品与推荐也是相同的方法