怎么调用商品规格?怎么改这段代码

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

我想在商品详细页里面调用礼包,礼包里面显示商品的属性规格,需要重新写过一个函数吗?
大家指点下。。。



  1. function get_goods_properties($goods_id)
  2. {
  3. /* 对属性进行重新排序和分组 */
  4. $sql = "SELECT attr_group ".
  5. "FROM " . $GLOBALS['ecs']->table('goods_type') . " AS gt, " . $GLOBALS['ecs']->table('goods') . " AS g ".
  6. "WHERE g.goods_id='$goods_id' AND gt.cat_id=g.goods_type";
  7. $grp = $GLOBALS['db']->getOne($sql);

  8. if (!empty($grp))
  9. {
  10. $groups = explode("\n", strtr($grp, "\r", ''));
  11. }

  12. /* 获得商品的规格 */
  13. $sql = "SELECT a.attr_id, a.attr_name, a.attr_group, a.is_linked, a.attr_type, ".
  14. "g.goods_attr_id, g.attr_value, g.attr_price " .
  15. 'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .
  16. 'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .
  17. "WHERE g.goods_id = '$goods_id' " .
  18. 'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
  19. $res = $GLOBALS['db']->getAll($sql);

  20. $arr['pro'] = array(); // 属性
  21. $arr['spe'] = array(); // 规格
  22. $arr['lnk'] = array(); // 关联的属性

  23. foreach ($res AS $row)
  24. {
  25. if ($row['attr_type'] == 0)
  26. {
  27. $group = (isset($groups[$row['attr_group']])) ? $groups[$row['attr_group']] : $GLOBALS['_LANG']['goods_attr'];

  28. $arr['pro'][$group][$row['attr_id']]['name'] = $row['attr_name'];
  29. $arr['pro'][$group][$row['attr_id']]['value'] = $row['attr_value'];
  30. }
  31. else
  32. {
  33. $arr['spe'][$row['attr_id']]['attr_type'] = $row['attr_type'];
  34. $arr['spe'][$row['attr_id']]['name'] = $row['attr_name'];
  35. $arr['spe'][$row['attr_id']]['values'][] = array(
  36. 'label' => $row['attr_value'],
  37. 'price' => $row['attr_price'],
  38. 'format_price' => price_format(abs($row['attr_price']), false),
  39. 'id' => $row['goods_attr_id']);
  40. }

  41. if ($row['is_linked'] == 1)
  42. {
  43. /* 如果该属性需要关联,先保存下来 */
  44. $arr['lnk'][$row['attr_id']]['name'] = $row['attr_name'];
  45. $arr['lnk'][$row['attr_id']]['value'] = $row['attr_value'];
  46. }
  47. }

  48. return $arr;
  49. }
复制代码