/** * Updates an existing Products model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $product = $this->findModel($id); $product_image = new ProductsImages(); if ($product->load(Yii::$app->request->post()) && $product->load_images(Yii::$app->request->post()) && $product->load_parameters(Yii::$app->request->post('ParametersValues')) && $product->load_categories(Yii::$app->request->post('cat_tree')) && $product->load_prices(Yii::$app->request->post('Prices'))) { if ($product->validate()) { if ($product->save(false)) { Yii::$app->session->setFlash('success', Yii::t('storecube', 'PRODUCT_CREATE_SUCCESS')); return $this->redirect(['update', 'id' => $product->id]); } else { Yii::$app->session->setFlash('danger', Yii::t('storecube', 'PRODUCT_CREATE_FAIL')); return $this->refresh(); } } elseif (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($product); } } else { return $this->render('update', ['product' => $product, 'product_image' => $product_image, 'statusArray' => Products::getStatusArray()]); } }