Пример #1
0
 /**
  * Save data action for ShopAttribute.
  * If user has not permissions to do this action, a 403 HTTP exception will be thrown.
  *
  * @param integer $languageId
  * @param integer $attrId
  * @return mixed
  * @throws ForbiddenHttpException if user has not permissions
  */
 public function actionSave($languageId = null, $attrId = null)
 {
     if (empty($languageId)) {
         $languageId = Language::getCurrent()->id;
     }
     $selectedLanguage = Language::findOne($languageId);
     $languages = Language::find()->all();
     $attributeType = ArrayHelper::toArray(ShopAttributeType::find()->all(), ['bl\\cms\\shop\\common\\entities\\ShopAttributeType' => ['id', 'title' => function ($attributeType) {
         return \Yii::t('shop', $attributeType->title);
     }]]);
     if (empty($attrId)) {
         $model = new ShopAttribute();
         $modelTranslation = new ShopAttributeTranslation();
         $searchAttributeValueModel = null;
         $dataProviderAttributeValue = null;
     } else {
         $searchAttributeValueModel = new SearchAttributeValue();
         $dataProviderAttributeValue = $searchAttributeValueModel->search(Yii::$app->request->queryParams);
         $model = ShopAttribute::findOne($attrId);
         $modelTranslation = ShopAttributeTranslation::find()->where(['attr_id' => $attrId, 'language_id' => $languageId])->one();
         if (empty($modelTranslation)) {
             $modelTranslation = new ShopAttributeTranslation();
         }
     }
     if (Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->post());
         $modelTranslation->load(Yii::$app->request->post());
         if ($model->validate()) {
             $model->save();
             $modelTranslation->attr_id = $model->id;
             $modelTranslation->language_id = $languageId;
         }
         if ($modelTranslation->validate()) {
             $modelTranslation->save();
             Yii::$app->getSession()->setFlash('success', 'Data were successfully modified.');
             return $this->redirect(['save', 'attrId' => $model->id, 'languageId' => $languageId]);
         }
     }
     return $this->render('save', ['attribute' => $model, 'attributeTranslation' => $modelTranslation, 'attributeType' => $attributeType, 'languages' => $languages, 'selectedLanguage' => $selectedLanguage, 'searchModel' => $searchAttributeValueModel, 'dataProvider' => $dataProviderAttributeValue, 'valueModel' => new ShopAttributeValue(), 'valueModelTranslation' => new ShopAttributeValueTranslation(), 'attributeTextureModel' => new AttributeTextureForm()]);
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['translation' => ['class' => TranslationBehavior::className(), 'translationClass' => ShopAttributeTranslation::className(), 'relationColumn' => 'attr_id'], 'timestamp' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']], 'value' => new Expression('NOW()')]];
 }