您现在的位置是:首页 > 教程 > ecshop商城教程ecshop商城教程

ecshop首页商品怎么实现随机排序

凌香2023-11-18 00:30:19ecshop商城教程已有人查阅

导读首页ecshop商品随机排序的三种方法都是修改inlcudes/lib_goods.php这个文件1 精品推荐  新品上架 热卖商品 促销商品 团购商品 拍卖商品 6类随机排序的调整方法

首页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()';

本文标签:

很赞哦! ()

留言与评论 (共有 条评论)
验证码:

本栏推荐

相关标签