public function add_to_cart () { if (!empty($_REQUEST['goods_id'])) { $goods_id = intval($_REQUEST['goods_id']); if($goods_id<=0){ $error['status'] = rpcLang("goods.php","parme_failure2"); $error['code'] = '1'; jsonExit($error); } } // $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => ''); // $json = new JSON; // // if (empty($_POST['goods'])) // { // $result['error'] = 1; // die($json->encode($result)); // } // // $goods = $json->decode($_POST['goods']); /* 检查:如果商品有规格,而post的数据没有规格,把商品的规格属性通过JSON传到前台 */ if (empty($_REQUEST['spec_str'])) { $spec_arr = array(); }else{ $spec_str = trim($_REQUEST['spec_str']); $spec_arr = split(",", $spec_str); } // /* 更新:如果是一步购物,先清空购物车 */ // if ($_CFG['one_step_buy'] == '1') // { // clear_cart(); // } if(empty($_REQUEST['parent_id'])){ $parent_id = 0; }else{ $parent_id = intval($_REQUEST['parent_id']); } /* 检查:商品数量是否合法 */ if (empty ($_REQUEST['buy_number'])||intval($_REQUEST['buy_number']) <= 0) { $buy_number = 1; } /* 更新:购物车 */ else { $buy_number = intval($_REQUEST['buy_number']); // 更新:添加到购物车 if (zy_addto_cart($goods_id, $buy_number, $spec_arr, $parent_id)) { $msg['status'] = rpcLang("goods.php","add_cart_success"); $msg['code'] = '0'; } else { $msg['status'] = rpcLang("goods.php","add_cart_failure"); $msg['code'] = '1'; } jsonExit($msg); } }
$parent_id = intval($_REQUEST['parent_id']); } /* 检查:商品数量是否合法 */ if (empty ($_REQUEST['buy_number'])||intval($_REQUEST['buy_number']) <= 0) { $buy_number = 1; } /* 更新:购物车 */ else { $buy_number = intval($_REQUEST['buy_number']); // 更新:添加到购物车 if (zy_addto_cart($goods_id, $buy_number, $spec_arr, $parent_id)) { $msg['status'] = rpcLang("goods.php","add_cart_success"); $msg['code'] = '0'; } else { $msg['status'] = rpcLang("goods.php","add_cart_failure"); $msg['code'] = '1'; } jsonExit($msg); } }