function add_to_cart_group()
{
$_POST['goods'] = strip_tags(urldecode($_POST['goods']));
$_POST['goods'] = json_str_iconv($_POST['goods']);
$result = array('error' => 0, 'message' => '');
$json = new EcsJson();
if (empty($_POST['goods']))
{
$result['error'] = 1;
$result['message'] = '系統(tǒng)無法接收不完整的數(shù)據(jù)';
die($json->encode($result));
}
$goods = $json->decode($_POST['goods']);
$group = $goods->group ."_". $goods->goods_id;//套餐組
//批量加入購物車
$sql = "SELECT rec_id FROM " . $this->model->pre . 'cart_combo' . " WHERE session_id = '" . SESS_ID . "'" .
" AND group_id = '". $group ."' ORDER BY parent_id limit 1";
$res = $this->model->query($sql);
if($res){
//清空購物車中的原有數(shù)據(jù)
$sql = "DELETE FROM " . $this->model->pre . 'cart' . " WHERE ".
" session_id='" . SESS_ID . "' AND group_id = '" . $group . "'";
$this->model->query($sql);
//插入新的數(shù)據(jù)
$sql = "INSERT INTO " . $this->model->pre . 'cart' . " SELECT * FROM " . $this->model->pre . 'cart_combo' . " WHERE ".
" session_id='" . SESS_ID . "' AND group_id = '" . $group . "'";
$this->model->query($sql);
//插入更新購物車商品數(shù)量
$sql = "UPDATE " . $this->model->pre . 'cart' . " set goods_number = '$goods->number' WHERE ".
" session_id='" . SESS_ID . "' AND group_id = '" . $group . "'";
$this->model->query($sql);
//清空套餐臨時數(shù)據(jù)
$sql = "DELETE FROM " . $this->model->pre . 'cart_combo' . " WHERE ".
" session_id='" . SESS_ID . "' AND group_id = '" . $group . "'";
$this->model->query($sql);
}else{
echo 2;exit();
$result['error'] = 1;
$result['message'] = '暫無數(shù)據(jù)可提交,請重新選擇';
die($json->encode($result));
}
$result['error'] = 0;
die($json->encode($result));
}
以上是由福州網(wǎng)站建設(shè)的小編為你分享了"ectouch將商品添加到購物車組函數(shù)"文章,如果你在這方面有什么問題,隨時聯(lián)系我們