frontend/controllers/AjaxController.php
/*
     * Remove item from cart
     * parameeters @cart_id
     * Return success if remove item from cart
     */
Remove item from cart
parameeters @cart_id
Return success if remove item from cart
Remove item from cart parameeters @cart_id Return success if remove item from cart
public function actionRemoveCart() {
        if (yii::$app->request->isAjax) {
            $id = Yii::$app->request->post()['id'];
            $condition = Yii::$app->CartFunctionality->UserCheck();
            $cart = Cart::find()->where(['id' => yii::$app->EncryptDecrypt->Encrypt('decrypt', $id)])->andWhere($condition)->one();
            if ($cart) {
                $cart->delete();
                $cart_contents = Cart::find()->where($condition)->all();
                $carrt_count = count($cart_contents);
                if (!empty($cart_contents)) {
                    $cart_data = $this->renderPartial('cart_contents', ['cart_contents' => $cart_contents]);
                } else {
                    $cart_data = '';
                }
                $arr_variable = array('content' => $cart_data, 'count' => $carrt_count, 'msg' => 'success', 'href' => Yii::$app->request->referrer);
                $data['result'] = $arr_variable;
                return json_encode($data);
            }
        }
    }
public function actionRemoveCart ( ) { if ( yii :: $ app -> request -> isAjax ) { $ id = Yii :: $ app -> request -> post ( ) [ 'id' ] ; $ condition = Yii :: $ app -> CartFunctionality -> UserCheck ( ) ; $ cart = Cart :: find ( ) -> where ( [ 'id' => yii :: $ app -> EncryptDecrypt -> Encrypt ( 'decrypt' , $ id ) ] ) -> andWhere ( $ condition ) -> one ( ) ; if ( $ cart ) { $ cart -> delete ( ) ; $ cart_contents = Cart :: find ( ) -> where ( $ condition ) -> all ( ) ; $ carrt_count = count ( $ cart_contents ) ; if ( ! empty ( $ cart_contents ) ) { $ cart_data = $ this -> renderPartial ( 'cart_contents' , [ 'cart_contents' => $ cart_contents ] ) ; } else { $ cart_data = '' ; } $ arr_variable = array ( 'content' => $ cart_data , 'count' => $ carrt_count , 'msg' => 'success' , 'href' => Yii :: $ app -> request -> referrer ) ; $ data [ 'result' ] = $ arr_variable ; return json_encode ( $ data ) ; } } }
Remove item from cart
 parameeters @cart_id
 Return success if remove item from cart
Remove item from cart parameeters @cart_id Return success if remove item from cart