后台商品的“推荐排序”数字越小优先排在前面,怎么实现呢?

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

首页商品按修改的时间先后排序的同时后台商品的“推荐排序”数字越小优先排在前面,怎么实现呢?

这是后台的图,有“推荐排序”的数字,在前台的显示如何实现按照修改时间排序的同时,“推荐排序”数字越小优先排在前面呢?
0000000000000000000.jpg



前台目前是默认的按照修改时间排序的。
1111111111111111111111111111.jpg

回答:
是不是在includes/lib_goods.php里面修改呀??这是代码


  1. * 获得指定分类下的按时间排序的前5个商品
  2. *
  3. * @access public
  4. * @param string $children
  5. * @return array
  6. */
  7. function category_get_last_update_goods($cat_id, $brand, $min, $max)
  8. {
  9. $children = get_children($cat_id);

  10. $display = $GLOBALS['display'];
  11. $where = "g.is_on_sale = 1 AND g.goods_number > 0 AND g.is_alone_sale = 1 AND ".
  12. "g.is_delete = 0 AND ($children)";

  13. if ($brand > 0)
  14. {
  15. $where .= "AND g.brand_id=$brand ";
  16. }

  17. if ($min > 0)
  18. {
  19. $where .= " AND g.shop_price >= $min ";
  20. }

  21. if ($max > 0)
  22. {
  23. $where .= " AND g.shop_price <= $max ";
  24. }

  25. /* 获得商品列表 */
  26. $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .
  27. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
  28. 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
  29. 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
  30. 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' .
  31. "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
  32. " WHERE $where ORDER BY g.last_update DESC";
  33. $res = $GLOBALS['db']->selectLimit($sql, 5, 0);

  34. $arr = array();
  35. while ($row = $GLOBALS['db']->fetchRow($res))
  36. {
  37. if ($row['promote_price'] > 0)
  38. {
  39. $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
  40. }
  41. else
  42. {
  43. $promote_price = 0;
  44. }

  45. /* 处理商品水印图片 */
  46. $watermark_img = '';

  47. if ($promote_price != 0)
  48. {
  49. $watermark_img = "watermark_promote_small";
  50. }
  51. elseif ($row['is_new'] != 0)
  52. {
  53. $watermark_img = "watermark_new_small";
  54. }
  55. elseif ($row['is_best'] != 0)
  56. {
  57. $watermark_img = "watermark_best_small";
  58. }
  59. elseif ($row['is_hot'] != 0)
  60. {
  61. $watermark_img = 'watermark_hot_small';
  62. }

  63. if ($watermark_img != '')
  64. {
  65. $arr[$row['goods_id']]['watermark_img'] = $watermark_img;
  66. }

  67. $arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
  68. if($display == 'grid')
  69. {
  70. $arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
  71. }
  72. else
  73. {
  74. $arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
  75. }
  76. $arr[$row['goods_id']]['name'] = $row['goods_name'];
  77. $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
  78. $arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
  79. $arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
  80. $arr[$row['goods_id']]['org_price'] = price_format($row['org_price']);
  81. $arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
  82. $arr[$row['goods_id']]['type'] = $row['goods_type'];
  83. $arr[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : '';
  84. $arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
  85. $arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
  86. $arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);

  87. $ranks = __get_user_rank_prices($row['goods_id'], $row['org_price']);
  88. $arr[$row['goods_id']]['ranks_price'] = $ranks;
  89. }

  90. return $arr;
  91. }
复制代码

不是。这个函数是你自己写的把。。。。首页分类推荐。不是在这个地方调用的

顶起顶起

顶起来啦




这是让别人二次开发的,模板本身没有这个功能,那是在哪个文件呢?增加一个按照推荐ID排序的语句进去就可以了吧,是哪个句子呢?

在模板调设置里的分类下商品,调去某一类商品时,推荐排序是没问题的,数字越小越靠前。在商品列表页,ecshop默认无法实现自定义排序。。。

我也需要此功能,帮顶起来



修改 includes/lib_goods.php 文件

ORDER BY g.sort_order, g.last_update DESC
改为
ORDER BYg.last_update DESC, g.sort_order


就这么简单,有好几处,都改掉,其实就是 两个排序字段 互换下位置

直接改数据库最方便