‘以下内容都是我在做ecshop相关的项目时碰到的问题,这里贴出来跟大家分享一下,也留着自己以后查用!
‘ 在首页出现,无疑我们肯定要传进去一个分类ID,如果还要指定为热销,就要传进去hot参数,EC系统是带有一个这样的函数的在includes/lib_goods.php中有如下函数
‘ 如果通过这个函数在index.php中smarty是可以的
‘ $smarty->assign(‘chot_goods_35’, get_category_recommend_goods(‘hot’,’35’)); //指定分类下的热销商品
‘ 其中hot指明为调用热销商品,35指定分类然后在index.dwt中调用
‘ <!–{foreach from=$chot_goods_35 item=goods}–>
‘ <div style=”padding-top: 8px;”>
‘ <a target=”_blank” href=”http://gaoyf68.blog.163.com/blog/{$goods.url}”><img width=”116″ height=”130″ border=”0″ alt=”{$goods.name|escape:html}” src=”http://gaoyf68.blog.163.com/blog/{$goods.thumb}”></a>
‘ <div>
‘ <a target=”_blank” href=”http://gaoyf68.blog.163.com/blog/{$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><a href=”javascript:addToCart({$goods.id})”>立即抢购</a></span>
‘ </div>
‘ <span></span>
‘ </div>
‘ <!–{/foreach}–>
‘ 如 果你测试下就会发现你调出的是所有商品的热销,不论你传进什么分类ID,它默认调出的都是所有商品的热销我们打印下SQL,然后到后台查询下发现也是调用 的所有分类下的热销商品问题在于function get_category_recommend_goods这个函数中的if (!empty($cats)) { $sql .= ” AND (” . $cats . ” OR ” . get_extension_goods($cats) .”)”; }这一句没起到作用,根本没有检索出所在分类ID下的热销改动方法将
‘ $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,g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ‘ .
‘ 查询出g.cat_id是商品的分类ID,然后把
‘ if (!empty($cats))
‘ {
‘ $sql .= ” AND (” . $cats. ” OR ” . get_extension_goods($cats) .”)”;
‘ }
‘ 改为
‘ if (!empty($cats))
‘ {
‘ $sql .= ” AND (g.cat_id =” . $cats. ” OR ” . get_extension_goods($cats) .”)”;
‘ }
‘ 加个限制,将ID为$cats的所有热销查询出来,也就是你要指定的分类ID下的热销商品然后在index.php中找到
‘ $smarty->assign(‘best_goods’, get_recommend_goods(‘best’)); // 推荐商品
‘ $smarty->assign(‘new_goods’, get_recommend_goods(‘new’)); // 新商品
‘ $smarty->assign(‘hot_goods’, get_recommend_goods(‘hot’)); // 热点文章
‘ 在下面加一个smarty$smarty->assign(‘chot_goods_35’, get_category_recommend_goods(‘hot’,’35’)); //指定分类下的热销商品注意35是商品的终分类ID,不是一级分类,二级分类ID,调出的也是这个二级分类所有的热销然后在模板中调用
‘ <!–{foreach from=$chot_goods_35 item=goods}–>
‘ <div style=”padding-top: 8px;”>
‘ <a target=”_blank” href=”http://gaoyf68.blog.163.com/blog/{$goods.url}”><img width=”116″ height=”130″ border=”0″ alt=”{$goods.name|escape:html}” src=”http://gaoyf68.blog.163.com/blog/{$goods.thumb}”></a>
‘ <div>
‘ <a target=”_blank” href=”http://gaoyf68.blog.163.com/blog/{$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><a href=”javascript:addToCart({$goods.id})”>立即抢购</a></span>
‘ </div>
‘ <span></span>
‘ </div>
‘ <!–{/foreach}–>以上方法实现的是子分类的热销商品调用,如果要实现一级分类的调用见2楼
‘ 以把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
‘$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;”>
‘ <a target=”_blank” href=”http://gaoyf68.blog.163.com/blog/{$goods.url}”><img width=”116″ height=”130″ border=”0″ alt=”{$goods.name|escape:html}” src=”http://gaoyf68.blog.163.com/blog/{$goods.thumb}”></a>
‘ <div>
‘ <a target=”_blank” href=”http://gaoyf68.blog.163.com/blog/{$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><a href=”javascript:addToCart({$goods.id})”>立即抢购</a></span>
‘ </div>
‘ <span></span>
‘ </div>
‘ <!–{/foreach}–>
‘ 同理,新品,推荐都可以调,只要把hot改为new 或者best就可以了欢迎大家跟帖讨论。
‘后鄙视依稀ecshop的官方论坛,既然都开源了,大家发布的解决各种问题的帖子为嘛要屏蔽掉?!!
上一篇: 5UCMS留言板插件开发指南
下一篇: 用5UCMS做日语网站碰到的一些小问题
游客回答:(0)