经典案例
  • 福州沐仙生建盏
  • 福建新路旅游文化传播有限公司
  • 宁德好记建材公司


ectouch将商品添加到购物车组函数

发布于:2017-12-06 20:58来源:福州网站制作 作者:福州网站建设 点击:
  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'] = '系统无法接收不完整的数据';
            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){
 
            //清空购物车中的原有数据
            $sql = "DELETE FROM " . $this->model->pre . 'cart' . " WHERE ".
                " session_id='" . SESS_ID . "' AND group_id = '" . $group . "'";
             $this->model->query($sql);
            //插入新的数据
            $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);
            //插入更新购物车商品数量
            $sql = "UPDATE " . $this->model->pre . 'cart' . " set goods_number = '$goods->number' WHERE ".
                " session_id='" . SESS_ID . "' AND group_id = '" . $group . "'";
            $this->model->query($sql);
            //清空套餐临时数据
            $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'] = '暂无数据可提交,请重新选择';
            die($json->encode($result));
        }
    
        $result['error']  = 0;
        die($json->encode($result));
    }
tag标签:
------分隔线----------------------------
------分隔线----------------------------