Ejemplo n.º 1
0
 /**
  * @param integer $attrId
  * @param integer $languageId
  * @return mixed
  * @throws Exception
  */
 public function actionAddValue($attrId, $languageId)
 {
     if (!empty($attrId)) {
         $languageId = empty($languageId) ? Language::getCurrent()->id : $languageId;
         $model = new ShopAttributeValue();
         $modelTranslation = new ShopAttributeValueTranslation();
         $attributeTextureModel = new AttributeTextureForm();
         if (Yii::$app->request->post()) {
             if ($modelTranslation->load(Yii::$app->request->post())) {
                 $model->attribute_id = $attrId;
                 if (ShopAttribute::findOne($attrId)->type_id == 3 || ShopAttribute::findOne($attrId)->type_id == 4) {
                     $colorTexture = new ShopAttributeValueColorTexture();
                     if (ShopAttribute::findOne($attrId)->type_id == 3) {
                         if ($attributeTextureModel->load(Yii::$app->request->post())) {
                             $colorTexture->color = $attributeTextureModel->color;
                         }
                     } elseif (ShopAttribute::findOne($attrId)->type_id == 4) {
                         if ($attributeTextureModel->load(Yii::$app->request->post())) {
                             $attributeTextureModel->imageFile = UploadedFile::getInstance($attributeTextureModel, 'imageFile');
                             $colorTexture->texture = $attributeTextureModel->upload();
                         }
                     }
                     $colorTexture->save();
                     $modelTranslation->value = $colorTexture->id;
                 }
                 if ($model->save()) {
                     $modelTranslation->value_id = $model->id;
                     $modelTranslation->language_id = $languageId;
                     if ($modelTranslation->save()) {
                         if (\Yii::$app->request->isPjax) {
                             $searchAttributeValueModel = new SearchAttributeValue();
                             $dataProviderAttributeValue = $searchAttributeValueModel->search(Yii::$app->request->queryParams);
                             return $this->renderPartial('add-value', ['dataProvider' => $dataProviderAttributeValue, 'attribute' => ShopAttribute::findOne($attrId), 'selectedLanguage' => Language::findOne($languageId), 'valueModel' => new ShopAttributeValue(), 'valueModelTranslation' => new ShopAttributeValueTranslation(), 'attributeTextureModel' => $attributeTextureModel]);
                         } else {
                             return $this->redirect(Url::toRoute(['save', 'attrId' => $attrId, 'languageId' => $languageId]));
                         }
                     }
                 } else {
                     throw new Exception($model->errors);
                 }
             }
         } else {
             return $this->render(Url::toRoute(['add-value', 'attrId' => $attrId, 'languageId' => $languageId]));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getShopAttributeValueTranslations()
 {
     return $this->hasMany(ShopAttributeValueTranslation::className(), ['value_id' => 'id']);
 }