ecshop首页如何调用指定分类商品

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

我们在做网站的时候经常会在首页调用不同分类,ecshop后台可以通过设置在前台调用指定分类,但是样式只有一种,如果有多个样式的话 这个方法就不行了。[url=http://www.phpmuban.com]php模板网[/url] 给大家提供一个ecshop教程,帮助大家更好的使用ecshop。
  1. /**

  2. * 获得分类下的商品

  3. *

  4. * @accesspublic

  5. * @paramstring$children

  6. * @returnarray

  7. */

  8. function get_index_goods($cat_id, $size=10, $page=1)

  9. {

  10. $children = get_children($cat_id);

  11. $display = $GLOBALS['display'];

  12. $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ".

  13. "g.is_delete = 0 AND ($children OR " . get_extension_goods($children) . ')';



  14. /* 获得商品列表 */

  15. $sql = 'SELECT g.goods_id, g.goods_name,g.is_hot,g.is_best, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .

  16. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .

  17. 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .

  18. 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .

  19. 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' .

  20. "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .

  21. "WHERE $where $ext ORDER BY goods_id DESC";

  22. $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);



  23. $arr = array();

  24. while ($row = $GLOBALS['db']->fetchRow($res))

  25. {

  26. if ($row['promote_price'] > 0)

  27. {

  28. $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);

  29. }

  30. else

  31. {

  32. $promote_price = 0;

  33. }



  34. /* 处理商品水印图片 */

  35. $watermark_img = '';



  36. if ($promote_price != 0)

  37. {

  38. $watermark_img = "watermark_promote_small";

  39. }

  40. elseif ($row['is_new'] != 0)

  41. {

  42. $watermark_img = "watermark_new_small";

  43. }

  44. elseif ($row['is_best'] != 0)

  45. {

  46. $watermark_img = "watermark_best_small";

  47. }

  48. elseif ($row['is_hot'] != 0)

  49. {

  50. $watermark_img = 'watermark_hot_small';

  51. }



  52. if ($watermark_img != '')

  53. {

  54. $arr[$row['goods_id']]['watermark_img'] =$watermark_img;

  55. }



  56. $arr[$row['goods_id']]['goods_id']= $row['goods_id'];

  57. if($display == 'grid')

  58. {

  59. $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'];

  60. }

  61. else

  62. {

  63. $arr[$row['goods_id']]['goods_name'] = $row['goods_name'];

  64. }

  65. $arr[$row['goods_id']]['name'] = $row['goods_name'];

  66. $arr[$row['goods_id']]['goods_brief']= $row['goods_brief'];

  67. $arr[$row['goods_id']]['short_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);

  68. $arr[$row['goods_id']]['market_price']= price_format($row['market_price']);

  69. $arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);

  70. $arr[$row['goods_id']]['type'] = $row['goods_type'];

  71. $arr[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : '';

  72. $arr[$row['goods_id']]['thumb']= get_image_path($row['goods_id'], $row['goods_thumb'], true);

  73. $arr[$row['goods_id']]['goods_img']= get_image_path($row['goods_id'], $row['goods_img']);

  74. $arr[$row['goods_id']]['is_hot']= $row['is_hot'];

  75. $arr[$row['goods_id']]['is_best']= $row['is_best'];

  76. $arr[$row['goods_id']]['is_new']= $row['is_new'];

  77. $arr[$row['goods_id']]['url']= build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);

  78. }



  79. return $arr;更多ecshop教程查看http://www.phpmuban.com

  80. }
复制代码

回答:
...............

看不懂啊,对PHP太菜,

能有简单点方法吗