diff --git a/common/modules/product/controllers/ManageController.php b/common/modules/product/controllers/ManageController.php index 6b56c18..495ae00 100755 --- a/common/modules/product/controllers/ManageController.php +++ b/common/modules/product/controllers/ManageController.php @@ -268,7 +268,13 @@ class ManageController extends Controller if ($model->load(Yii::$app->request->post())) { $file = UploadedFile::getInstances($model, 'file'); $method = 'go'. ucfirst($model->type); - if (!empty($file) && $model->validate()) { + if (empty($file)) { + $model->errors[] = 'File not upload'; + } elseif ($method == 'goPrices' && $file[0]->name != 'file_1.csv') { + $model->errors[] = 'File need "file_1.csv"'; + } elseif ($method == 'goProducts' && $file[0]->name == 'file_1.csv') { + $model->errors[] = 'File can not "file_1.csv"'; + } elseif ($model->validate()) { $file[0]->saveAs(Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@uploadFile'. ucfirst($model->type))); $model->$method(); } diff --git a/common/modules/product/controllers/ProductVariantTypeController.php b/common/modules/product/controllers/ProductVariantTypeController.php new file mode 100644 index 0000000..840f498 --- /dev/null +++ b/common/modules/product/controllers/ProductVariantTypeController.php @@ -0,0 +1,124 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all ProductVariantType models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new ProductVariantTypeSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single ProductVariantType model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new ProductVariantType model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new ProductVariantType(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->product_variant_type_id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing ProductVariantType model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->product_variant_type_id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing ProductVariantType model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the ProductVariantType model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return ProductVariantType the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = ProductVariantType::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/common/modules/product/models/import.php b/common/modules/product/models/import.php index 6737fa2..f1de8f5 100644 --- a/common/modules/product/models/import.php +++ b/common/modules/product/models/import.php @@ -32,7 +32,7 @@ class Import extends Model { return [ [['type'], 'required'], [['type'], 'string'], - [['file'], 'safe'], +// [['file'], 'safe'], [['file'], 'file', 'extensions' => 'csv'], ]; } diff --git a/common/modules/product/views/product-variant-type/_form.php b/common/modules/product/views/product-variant-type/_form.php new file mode 100644 index 0000000..f0a7cfc --- /dev/null +++ b/common/modules/product/views/product-variant-type/_form.php @@ -0,0 +1,25 @@ + + +
+ = Html::a(Yii::t('product', 'Create Product Variant Type'), ['create'], ['class' => 'btn btn-success']) ?> +
+ = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + 'name', + 'name2', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> ++ = Html::a(Yii::t('product', 'Update'), ['update', 'id' => $model->product_variant_type_id], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('product', 'Delete'), ['delete', 'id' => $model->product_variant_type_id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('product', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'product_variant_type_id', + 'name', + 'name2', + ], + ]) ?> + +