예제 #1
0
 public function actionSave($id = null, $languageId = null)
 {
     $selectedLanguage = Language::findOne($languageId);
     if (!empty($id)) {
         $country = ProductCountry::find()->where(['id' => $id])->one();
         $countryTranslation = ProductCountryTranslation::find()->where(['country_id' => $id, 'language_id' => $languageId])->one();
         if (empty($countryTranslation)) {
             $countryTranslation = new ProductCountryTranslation();
         }
     } else {
         $country = new ProductCountry();
         $countryTranslation = new ProductCountryTranslation();
     }
     if (\Yii::$app->request->isPost) {
         $country->load(\Yii::$app->request->post());
         $countryTranslation->load(\Yii::$app->request->post());
         if ($countryTranslation->validate()) {
             $country->save();
             $countryTranslation->country_id = $country->id;
             $countryTranslation->language_id = $selectedLanguage->id;
             $countryTranslation->save();
             return $this->redirect(Url::toRoute('/shop/country'));
         }
     }
     return $this->render('save', ['country' => $country, 'countryTranslation' => $countryTranslation, 'languages' => Language::findAll(['active' => true]), 'selectedLanguage' => $selectedLanguage]);
 }
예제 #2
0
 public function getTranslations()
 {
     return $this->hasMany(ProductCountryTranslation::className(), ['country_id' => 'id']);
 }