goods.php里面添加到购物车里面$goods->all什么意思?

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

$goods = $json->decode($_POST['goods']);

if($goods->all==1){
  1. /*------------------------------------------------------ */
  2. //-- 添加商品到购物车
  3. /*------------------------------------------------------ */
  4. if ($_REQUEST['step'] == 'add_to_cart')
  5. {
  6. include_once('includes/cls_json.php');
  7. $_POST['goods'] = json_str_iconv($_POST['goods']);

  8. if (!empty($_REQUEST['goods_id']) && empty($_POST['goods']))
  9. {
  10. if (!is_numeric($_REQUEST['goods_id']) || intval($_REQUEST['goods_id']) <= 0)
  11. {
  12. ecs_header("Location:./\n");
  13. }
  14. $goods_id = intval($_REQUEST['goods_id']);
  15. exit;
  16. }

  17. $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '');
  18. $json= new JSON;

  19. if (empty($_POST['goods']))
  20. {
  21. $result['error'] = 1;
  22. die($json->encode($result));
  23. }

  24. $goods = $json->decode($_POST['goods']);

  25. if($goods->all==1){
  26. if (empty($goods->spec)){
  27. $sql = "SELECT a.attr_id, a.attr_name, a.attr_type, ".
  28. "g.goods_attr_id, g.attr_value, g.attr_price " .
  29. 'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .
  30. 'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .
  31. "WHERE a.attr_type= 1 AND g.goods_id = '" . $goods->goods_id . "' " .
  32. 'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
  33. $spec_a = $GLOBALS['db']->getAll($sql);
  34. }
  35. if(count($spec_a)>0){
  36. $temp=$spec_a[0]['attr_id'];
  37. $goods->spec[]=$spec_a[0]['goods_attr_id'];
  38. for($i=0;$i<count($spec_a);$i++){
  39. if($spec_a[$i]['attr_id']==$temp){
  40. continue;
  41. }else{
  42. $goods->spec[]=$spec_a[$i]['goods_attr_id'];
  43. $temp=$spec_a[$i]['attr_id'];
  44. }
  45. }
  46. }
  47. }
复制代码