/**
  * Creates a new DeliveryMethod model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @param integer $languageId
  * @return mixed
  * @throws NotFoundHttpException
  * @throws BadRequestHttpException
  */
 public function actionSave($id = null, $languageId)
 {
     if (!empty($languageId)) {
         if (!empty($id)) {
             $model = $this->findModel($id);
             if (empty($model)) {
                 throw new NotFoundHttpException();
             }
             $modelTranslation = $this->findModelTranslation($id, $languageId);
             if (empty($modelTranslation)) {
                 $modelTranslation = new ProductAvailabilityTranslation();
             }
         } else {
             $model = new ProductAvailability();
             $modelTranslation = new ProductAvailabilityTranslation();
         }
     } else {
         throw new BadRequestHttpException();
     }
     if ($modelTranslation->load(Yii::$app->request->post())) {
         $model->save(false);
         $modelTranslation->availability_id = $model->id;
         $modelTranslation->language_id = $languageId;
         if ($modelTranslation->validate()) {
             $modelTranslation->save();
             return $this->redirect(['save', 'id' => $model->id, 'languageId' => $languageId]);
         }
     }
     return $this->render('save', ['model' => $model, 'modelTranslation' => $modelTranslation, 'languages' => Language::find()->all(), 'selectedLanguage' => Language::findOne($languageId)]);
 }