福州网站建设>网站新闻>php技术

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

发布日期:2017-12-06浏览次数:1003 来源:福州网站建设

  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));
    }

以上是由福州网站建设的小编为你分享了"ectouch将商品添加到购物车组函数"文章,如果你在这方面有什么问题,随时联系我们

php技术有关的文章
如果您有什么问题,欢迎咨询我们客服! 点击QQ咨询