ecshop首页调用指定分类下的推荐、热卖、新品
时间:2024年02月04日
/来源:网络
/编辑:佚名
默认情况下ECSHOP首页的推荐、热卖和新品三个板块的商品都是从所有商品里读取出来的。
如果要“在ecshop首页调用指定分类的推荐、热卖、新品?”该怎么办呢?
下面教你一种方法.
找到 ecshop 的 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, ' .
----------------------------------------------------------------------------------------------
继续找到
----------------------------------------------------------------------------------------------
'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) .")";
}
----------------------------------------------------------------------------------------------
这个是和分类表建立关联,调出商品所在分类的上级分类
然后在index.php中增加下面代码
$smarty->assign('chot_goods_35', get_category_recommend_goods('hot','35')); //指定分类下的热销商品
注意:这个35是一级分类的ID,然后在模板中调用即可
----------------------------------------------------------------------------------------------
<!--{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 class="right">
<a target="_blank" href="{$goods.url}">{$goods.name|escape:html}</a><br>
<span style="color: rgb(102, 102, 102); text-decoration: line-through;">市场价:{$goods.market_price}</span><br>
特卖价:<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}-->
----------------------------------------------------------------------------------------------
同理,新品,推荐都可以调,只需要把hot 改为 new 或者 best 就OK了。
如果要“在ecshop首页调用指定分类的推荐、热卖、新品?”该怎么办呢?
下面教你一种方法.
找到 ecshop 的 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, ' .
----------------------------------------------------------------------------------------------
继续找到
----------------------------------------------------------------------------------------------
'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) .")";
}
----------------------------------------------------------------------------------------------
这个是和分类表建立关联,调出商品所在分类的上级分类
然后在index.php中增加下面代码
$smarty->assign('chot_goods_35', get_category_recommend_goods('hot','35')); //指定分类下的热销商品
注意:这个35是一级分类的ID,然后在模板中调用即可
----------------------------------------------------------------------------------------------
<!--{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 class="right">
<a target="_blank" href="{$goods.url}">{$goods.name|escape:html}</a><br>
<span style="color: rgb(102, 102, 102); text-decoration: line-through;">市场价:{$goods.market_price}</span><br>
特卖价:<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}-->
----------------------------------------------------------------------------------------------
同理,新品,推荐都可以调,只需要把hot 改为 new 或者 best 就OK了。
新闻资讯 更多
热门文章
- 178Moban源码谈谈免费源码与收费源码的区别
- 2帝国CMS忘记后台登陆用户名、密码、认证码的解决方法
- 3帝国CMS(EmpireCMS) v7.5后台任意代码执行漏洞及具体修复方法
- 4帝国CMS和WordPress 哪个好?哪个适合建站?
- 5如何解决Discuz的密码错误次数过多请15分钟后登陆的问题
- 6帝国cms灵动标签取得内容和栏目链接地址
- 7emlog pro 注册码“开心”教程(如果有一天,emlog官方版 或者 emlog免费版 跑路了,那用户怎么办?)
- 8织梦CMS在nginx下设置伪静态方法(附nginx伪静态规则)
- 9帝国cms后台登录出现”您还未登录”怎么解决?
- 10帝国cms7.5忘记登录密码 和忘记登录认证码以及多次登录 失败被锁定解决办法