backend/modules/product/controllers/ProductController.php
/**
     * Updates an existing Product model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     */
Updates an existing Product model.
If update is successful, the browser will be redirected to the 'view' page.
@param integer $id
@return mixed
Updates an existing Product model . If update is successful the browser will be redirected to the ' view ' page . @param integer $id @return mixed
public function actionUpdate($id) {
        $model = $this->findModel($id);
        $profile = $model->profile;
        $canonical_name = $model->canonical_name;
        if ($model->load(Yii::$app->request->post())) {
            $ai = '';
            if (isset($model->type) && $model->type != '') {
                $model->type = implode(',', $model->type);
            }
            if (isset($model->related_product) && $model->related_product != '') {
                $model->related_product = implode(',', $model->related_product);
            }
            $file11 = UploadedFile::getInstances($model, 'profile');
            $file12 = UploadedFile::getInstances($model, 'other_image');
            if ($file11) {
                $model->profile = $file11[0]->extension;
            } else {
                $model->profile = $profile;
            }
            if ($canonical_name != $model->canonical_name) {
                $this->rename($model->id, $model->canonical_name, 'profile');
                $this->rename($model->id, $model->canonical_name, 'gallery');
                $this->rename($model->id, $model->canonical_name, 'gallery_thumb');
            }
            if (isset($model->search_tag) && $model->search_tag != '') {
                $model->search_tag = implode(',', $model->search_tag);
            }
            if (isset($model->offer_price_expiry_date) && $model->offer_price_expiry_date != '')
                $model->offer_price_expiry_date = date('Y-m-d', strtotime($model->offer_price_expiry_date));
            $model->other_image = '';
            if ($model->offer_price > 0 && $model->offer_price != '') {
                $percentage = round(100 - (($model->offer_price / $model->price) * 100));
                $model->discount = $percentage;
            }
            if ($model->save()) {
                if ($file11) {
                    $this->profile_clear($model);
                    if ($this->upload($model, $file11[0])) {
                        $model->upload($file11[0], $model);
                    }
                }
                for ($i = 0; $i < sizeof($file12); $i++) {
                    if ($model->uploadMultiple($file12[$i], $model->id, $model->canonical_name, $i)) {
                    } else {
                        echo 'Image Upload Failed:';
                    }
                }
                Yii::$app->getSession()->setFlash('success', "Updated Successfully");
                return $this->redirect(['update', 'id' => $model->id]);
            }
        }
        return $this->render('update', [
                    'model' => $model,
        ]);
    }
public function actionUpdate ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ profile = $ model -> profile ; $ canonical_name = $ model -> canonical_name ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { $ ai = '' ; if ( isset ( $ model -> type ) && $ model -> type != '' ) { $ model -> type = implode ( ',' , $ model -> type ) ; } if ( isset ( $ model -> related_product ) && $ model -> related_product != '' ) { $ model -> related_product = implode ( ',' , $ model -> related_product ) ; } $ file11 = UploadedFile :: getInstances ( $ model , 'profile' ) ; $ file12 = UploadedFile :: getInstances ( $ model , 'other_image' ) ; if ( $ file11 ) { $ model -> profile = $ file11 [ 0 ] -> extension ; } else { $ model -> profile = $ profile ; } if ( $ canonical_name != $ model -> canonical_name ) { $ this -> rename ( $ model -> id , $ model -> canonical_name , 'profile' ) ; $ this -> rename ( $ model -> id , $ model -> canonical_name , 'gallery' ) ; $ this -> rename ( $ model -> id , $ model -> canonical_name , 'gallery_thumb' ) ; } if ( isset ( $ model -> search_tag ) && $ model -> search_tag != '' ) { $ model -> search_tag = implode ( ',' , $ model -> search_tag ) ; } if ( isset ( $ model -> offer_price_expiry_date ) && $ model -> offer_price_expiry_date != '' ) $ model -> offer_price_expiry_date = date ( 'Y-m-d' , strtotime ( $ model -> offer_price_expiry_date ) ) ; $ model -> other_image = '' ; if ( $ model -> offer_price > 0 && $ model -> offer_price != '' ) { $ percentage = round ( 100 - ( ( $ model -> offer_price / $ model -> price ) * 100 ) ) ; $ model -> discount = $ percentage ; } if ( $ model -> save ( ) ) { if ( $ file11 ) { $ this -> profile_clear ( $ model ) ; if ( $ this -> upload ( $ model , $ file11 [ 0 ] ) ) { $ model -> upload ( $ file11 [ 0 ] , $ model ) ; } } for ( $ i = 0 ; $ i < sizeof ( $ file12 ) ; $ i ++ ) { if ( $ model -> uploadMultiple ( $ file12 [ $ i ] , $ model -> id , $ model -> canonical_name , $ i ) ) { } else { echo 'Image Upload Failed:' ; } } Yii :: $ app -> getSession ( ) -> setFlash ( 'success' , " Updated Successfully " ) ; return $ this -> redirect ( [ 'update' , 'id' => $ model -> id ] ) ; } } return $ this -> render ( 'update' , [ 'model' => $ model , ] ) ; }
Updates an existing Product model.
Updates an existing Product model .