modules/api/v1/controllers/CartItemController.php
/**
     * Updates an existing CartItem model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
Updates an existing CartItem model.
If update is successful, the browser will be redirected to the 'view' page.
@param integer $id
@return mixed
@throws NotFoundHttpException if the model cannot be found
Updates an existing CartItem model . If update is successful the browser will be redirected to the ' view ' page . @param integer $id @return mixed @throws NotFoundHttpException if the model cannot be found
public function actionUpdate($id)
    {
        $model = CartItem::findOne($id);
        if (!$model instanceof CartItem) {
            throw new NotFoundHttpException('Cart item doesn\'t exist.');
        }
        $postData = Yii::$app->request->post();
        $cartIteam['CartItem'] = $postData;
        $cartIteam['CartItem']['user_id'] = Yii::$app->user->identity->id;
        if ($model->load($cartIteam) && $model->validate()) {
            $productData = Product::find()->where(['id' => $model->product_id])->one();
            $basePrice = (!empty($productData) && $productData instanceof Product && !empty($productData->price)) ? $productData->price * $model->quantity : 0;
            $taxPrice = (!empty($productData) && $productData instanceof Product && !empty($productData->option_price)) ? $productData->option_price * $model->quantity : 0;
            $model->price = ($basePrice + $taxPrice);
            $model->save();
        }
        return $model;
    }
public function actionUpdate ( $ id ) { $ model = CartItem :: findOne ( $ id ) ; if ( ! $ model instanceof CartItem ) { throw new NotFoundHttpException ( 'Cart item doesn\'t exist.' ) ; } $ postData = Yii :: $ app -> request -> post ( ) ; $ cartIteam [ 'CartItem' ] = $ postData ; $ cartIteam [ 'CartItem' ] [ 'user_id' ] = Yii :: $ app -> user -> identity -> id ; if ( $ model -> load ( $ cartIteam ) && $ model -> validate ( ) ) { $ productData = Product :: find ( ) -> where ( [ 'id' => $ model -> product_id ] ) -> one ( ) ; $ basePrice = ( ! empty ( $ productData ) && $ productData instanceof Product && ! empty ( $ productData -> price ) ) ? $ productData -> price * $ model -> quantity : 0 ; $ taxPrice = ( ! empty ( $ productData ) && $ productData instanceof Product && ! empty ( $ productData -> option_price ) ) ? $ productData -> option_price * $ model -> quantity : 0 ; $ model -> price = ( $ basePrice + $ taxPrice ) ; $ model -> save ( ) ; } return $ model ; }
Updates an existing CartItem model.
Updates an existing CartItem model .