Ejemplo n.º 1
0
 /**
  * Update param translation.
  * Users which have 'updateOwnProduct' permission can update params only for Product models that have been created by their.
  * Users which have 'updateProduct' permission can update params for all Product models.
  *
  * @param int $id
  * @param int $languageId
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionUpdateParam(int $id, int $languageId)
 {
     if (!empty($id) && !empty($languageId)) {
         $paramTranslation = ParamTranslation::find()->where(['param_id' => $id, 'language_id' => $languageId])->one();
         if (empty($paramTranslation)) {
             $paramTranslation = new ParamTranslation();
             $paramTranslation->param_id = $id;
             $paramTranslation->language_id = $languageId;
         }
         if (Yii::$app->request->isPost) {
             $paramTranslation->load(Yii::$app->request->post());
             if ($paramTranslation->validate()) {
                 $paramTranslation->save();
                 Yii::$app->getSession()->setFlash('success', 'Data were successfully modified.');
             } else {
                 Yii::$app->getSession()->setFlash('danger', 'Failed to change the record.');
             }
             return $this->redirect(['add-param', 'id' => $paramTranslation->param->product_id, 'languageId' => $languageId]);
         }
         return $this->renderPartial('update-param', ['paramTranslation' => $paramTranslation, 'languageId' => $languageId]);
     } else {
         throw new NotFoundHttpException();
     }
 }