ECSHOP首页商品随机排序的三种方法

2016-07-07 15:12 来源:www.chinab4c.com 作者:ecshop专家

首页商品随机排序的三种方法

都是修改inlcudes/lib_goods.php这个文件
1 精品推荐新品上架 热卖商品 促销商品 团购商品 拍卖商品 6类随机排序的调整方法
    将$order_type = 0;改为$order_type = 1
2 修改“分类下的商品”排列顺序为随机
将assign_cat_goods这个函数中的sql
$sql = 'SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
'g.promote_price, promote_start_date, 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 g.is_on_sale = 1 AND g.is_alone_sale = 1 AND '.
'g.is_delete = 0 AND (' . $children . 'OR ' . get_extension_goods($children) . ') ' .
'ORDER BY g.sort_order, g.goods_id DESC';
改为
$order_type = 1;
$sql = 'SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
'g.promote_price, promote_start_date, 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 g.is_on_sale = 1 AND g.is_alone_sale = 1 AND '.
'g.is_delete = 0 AND (' . $children . 'OR ' . get_extension_goods($children) . ') ' ;

$sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.goods_id DESC' : ' ORDER BY RAND()';
其实就是在第一行加上一句“$order_type = 1;”,在最后一行的前面加上“$sql .= $order_type == 0 ? ”,后面加上“ : ' ORDER BY RAND()'”,别忘了是在最后的“;”之前

3 修改“品牌的商品”排列顺序为随机
在assign_brand_goods这个函数的前面加入一句“$order_type = 1;”,将该函数下方第五行的“$sql .= ' ORDER BY g.sort_order, g.goods_id DESC';”改为“$sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.goods_id DESC' : ' ORDER BY RAND()';”即可
就是将
function assign_brand_goods($brand_id, $num = 0, $cat_id = 0)
{
$sql ='SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
'g.promote_price, 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 g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.brand_id = '$brand_id'";
if ($cat_id > 0)
{
$sql .= get_children($cat_id);
}
$sql .= ' ORDER BY g.sort_order, g.goods_id DESC';

改为
function assign_brand_goods($brand_id, $num = 0, $cat_id = 0)
{
$order_type = 1;
$sql ='SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
'g.promote_price, 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 g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.brand_id = '$brand_id'";
if ($cat_id > 0)
{
$sql .= get_children($cat_id);
}
$sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.goods_id DESC' : ' ORDER BY RAND()';
上面就是我的做法,实际应用也达到了预期的效果,帖出来也大家共享,有不同方法还望与大家共同讨论。
谢谢!

---------这篇文章是百度找的,不是本人原创

回答:
感觉改得好多,现在不敢随便改代码

实际运营的,总怕问题出现!

好东西..先收藏了

为何我试了而没有效果呢?

我现在都是用默认的模板了,没什么大的必要不怎么想动多少

这个功能不错,会有一天需要的。

不能用啊,~
http://www.yihongge.com

原帖由 幸福泉珠帘 于 2008-9-1 10:42 发表
我现在都是用默认的模板了,没什么大的必要不怎么想动多少


楼主,我加你QQ了,有总是请教

需要手工排序。

留个记号备用

我按照你的改了,没有效果呀?
我的网站:www.chayechaoshi.com

这么多人都说没用 究竟能用不???先改改试试 谢谢楼主咯

我没用过,改这么多也很麻烦的植美村

如果我要指定某些商品排到首页,如何处理?

同留记号