商品列表也显示获赠消费积分

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家

有的客户会要求把每个商品的获赠积分显示在商品列表页:

1、打开category.php 找到 category_get_goods 函数 修改为
  1. function category_get_goods($children, $brand, $min, $max, $ext, $size, $page, $sort, $order)
  2. {
  3. $display = $GLOBALS['display'];
  4. $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ".
  5. "g.is_delete = 0 AND ($children OR " . get_extension_goods($children) . ')';

  6. if ($brand > 0)
  7. {
  8. $where .= "AND g.brand_id=$brand ";
  9. }

  10. if ($min > 0)
  11. {
  12. $where .= " AND g.shop_price >= $min ";
  13. }

  14. if ($max > 0)
  15. {
  16. $where .= " AND g.shop_price <= $max ";
  17. }

  18. /* 获得商品列表 */
  19. $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, IF(g.give_integral > -1, g.give_integral, g.shop_price) as integral, ' .


  20. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
  21. 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
  22. 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
  23. 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' .
  24. "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
  25. "WHERE $where $ext ORDER BY $sort $order";
  26. $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);

  27. $arr = array();
  28. while ($row = $GLOBALS['db']->fetchRow($res))
  29. {
  30. $goods_id = $row['goods_id'];
  31. $sql2= "select sum(goods_number) as count from ".$GLOBALS['ecs']->table('order_goods')."where goods_id ='".$goods_id."'";
  32. $buy_num = $GLOBALS['db']->getOne($sql2);
  33. if ($row['promote_price'] > 0)
  34. {
  35. $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
  36. }
  37. else
  38. {
  39. $promote_price = 0;
  40. }

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

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

  59. if ($watermark_img != '')
  60. {
  61. $arr[$row['goods_id']]['watermark_img'] = $watermark_img;
  62. }

  63. $arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
  64. if($display == 'grid')
  65. {
  66. $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'];
  67. }
  68. else
  69. {
  70. $arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
  71. }
  72. $arr[$row['goods_id']]['count'] = $buy_num;
  73. $arr[$row['goods_id']]['name'] = $row['goods_name'];
  74. /* 修正积分:转换为可使用多少积分(原来是可以使用多少钱的积分) */
  75. $arr[$row['goods_id']]['integral'] = round($row['integral'],0);

  76. $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
  77. $arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
  78. $arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
  79. $arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
  80. $arr[$row['goods_id']]['type'] = $row['goods_type'];
  81. $arr[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : '';
  82. $arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
  83. $arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
  84. $arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
  85. }

  86. return $arr;
  87. }
复制代码

2、模板部分直接加
  1. {$goods.integral}积分
复制代码

回答:
這個意思是我們自己找位置放嗎?

看起来好像很复杂的样子