Commit 10e0f427440b7e9319c9fbf5b8544d1581ad4c0e
1 parent
a57c9f4d
-
Showing
9 changed files
with
301 additions
and
2 deletions
Show diff stats
common/modules/product/controllers/ManageController.php
@@ -268,7 +268,13 @@ class ManageController extends Controller | @@ -268,7 +268,13 @@ class ManageController extends Controller | ||
268 | if ($model->load(Yii::$app->request->post())) { | 268 | if ($model->load(Yii::$app->request->post())) { |
269 | $file = UploadedFile::getInstances($model, 'file'); | 269 | $file = UploadedFile::getInstances($model, 'file'); |
270 | $method = 'go'. ucfirst($model->type); | 270 | $method = 'go'. ucfirst($model->type); |
271 | - if (!empty($file) && $model->validate()) { | 271 | + if (empty($file)) { |
272 | + $model->errors[] = 'File not upload'; | ||
273 | + } elseif ($method == 'goPrices' && $file[0]->name != 'file_1.csv') { | ||
274 | + $model->errors[] = 'File need "file_1.csv"'; | ||
275 | + } elseif ($method == 'goProducts' && $file[0]->name == 'file_1.csv') { | ||
276 | + $model->errors[] = 'File can not "file_1.csv"'; | ||
277 | + } elseif ($model->validate()) { | ||
272 | $file[0]->saveAs(Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@uploadFile'. ucfirst($model->type))); | 278 | $file[0]->saveAs(Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@uploadFile'. ucfirst($model->type))); |
273 | $model->$method(); | 279 | $model->$method(); |
274 | } | 280 | } |
common/modules/product/controllers/ProductVariantTypeController.php
0 โ 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace common\modules\product\controllers; | ||
4 | + | ||
5 | +use Yii; | ||
6 | +use common\modules\product\models\ProductVariantType; | ||
7 | +use common\modules\product\models\ProductVariantTypeSearch; | ||
8 | +use yii\web\Controller; | ||
9 | +use yii\web\NotFoundHttpException; | ||
10 | +use yii\filters\VerbFilter; | ||
11 | + | ||
12 | +/** | ||
13 | + * ProductVariantTypeController implements the CRUD actions for ProductVariantType model. | ||
14 | + */ | ||
15 | +class ProductVariantTypeController extends Controller | ||
16 | +{ | ||
17 | + /** | ||
18 | + * @inheritdoc | ||
19 | + */ | ||
20 | + public function behaviors() | ||
21 | + { | ||
22 | + return [ | ||
23 | + 'verbs' => [ | ||
24 | + 'class' => VerbFilter::className(), | ||
25 | + 'actions' => [ | ||
26 | + 'delete' => ['POST'], | ||
27 | + ], | ||
28 | + ], | ||
29 | + ]; | ||
30 | + } | ||
31 | + | ||
32 | + /** | ||
33 | + * Lists all ProductVariantType models. | ||
34 | + * @return mixed | ||
35 | + */ | ||
36 | + public function actionIndex() | ||
37 | + { | ||
38 | + $searchModel = new ProductVariantTypeSearch(); | ||
39 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | ||
40 | + | ||
41 | + return $this->render('index', [ | ||
42 | + 'searchModel' => $searchModel, | ||
43 | + 'dataProvider' => $dataProvider, | ||
44 | + ]); | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * Displays a single ProductVariantType model. | ||
49 | + * @param integer $id | ||
50 | + * @return mixed | ||
51 | + */ | ||
52 | + public function actionView($id) | ||
53 | + { | ||
54 | + return $this->render('view', [ | ||
55 | + 'model' => $this->findModel($id), | ||
56 | + ]); | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * Creates a new ProductVariantType model. | ||
61 | + * If creation is successful, the browser will be redirected to the 'view' page. | ||
62 | + * @return mixed | ||
63 | + */ | ||
64 | + public function actionCreate() | ||
65 | + { | ||
66 | + $model = new ProductVariantType(); | ||
67 | + | ||
68 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||
69 | + return $this->redirect(['view', 'id' => $model->product_variant_type_id]); | ||
70 | + } else { | ||
71 | + return $this->render('create', [ | ||
72 | + 'model' => $model, | ||
73 | + ]); | ||
74 | + } | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * Updates an existing ProductVariantType model. | ||
79 | + * If update is successful, the browser will be redirected to the 'view' page. | ||
80 | + * @param integer $id | ||
81 | + * @return mixed | ||
82 | + */ | ||
83 | + public function actionUpdate($id) | ||
84 | + { | ||
85 | + $model = $this->findModel($id); | ||
86 | + | ||
87 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||
88 | + return $this->redirect(['view', 'id' => $model->product_variant_type_id]); | ||
89 | + } else { | ||
90 | + return $this->render('update', [ | ||
91 | + 'model' => $model, | ||
92 | + ]); | ||
93 | + } | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * Deletes an existing ProductVariantType model. | ||
98 | + * If deletion is successful, the browser will be redirected to the 'index' page. | ||
99 | + * @param integer $id | ||
100 | + * @return mixed | ||
101 | + */ | ||
102 | + public function actionDelete($id) | ||
103 | + { | ||
104 | + $this->findModel($id)->delete(); | ||
105 | + | ||
106 | + return $this->redirect(['index']); | ||
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * Finds the ProductVariantType model based on its primary key value. | ||
111 | + * If the model is not found, a 404 HTTP exception will be thrown. | ||
112 | + * @param integer $id | ||
113 | + * @return ProductVariantType the loaded model | ||
114 | + * @throws NotFoundHttpException if the model cannot be found | ||
115 | + */ | ||
116 | + protected function findModel($id) | ||
117 | + { | ||
118 | + if (($model = ProductVariantType::findOne($id)) !== null) { | ||
119 | + return $model; | ||
120 | + } else { | ||
121 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
122 | + } | ||
123 | + } | ||
124 | +} |
common/modules/product/models/import.php
@@ -32,7 +32,7 @@ class Import extends Model { | @@ -32,7 +32,7 @@ class Import extends Model { | ||
32 | return [ | 32 | return [ |
33 | [['type'], 'required'], | 33 | [['type'], 'required'], |
34 | [['type'], 'string'], | 34 | [['type'], 'string'], |
35 | - [['file'], 'safe'], | 35 | +// [['file'], 'safe'], |
36 | [['file'], 'file', 'extensions' => 'csv'], | 36 | [['file'], 'file', 'extensions' => 'csv'], |
37 | ]; | 37 | ]; |
38 | } | 38 | } |
common/modules/product/views/product-variant-type/_form.php
0 โ 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Html; | ||
4 | +use yii\widgets\ActiveForm; | ||
5 | + | ||
6 | +/* @var $this yii\web\View */ | ||
7 | +/* @var $model common\modules\product\models\ProductVariantType */ | ||
8 | +/* @var $form yii\widgets\ActiveForm */ | ||
9 | +?> | ||
10 | + | ||
11 | +<div class="product-variant-type-form"> | ||
12 | + | ||
13 | + <?php $form = ActiveForm::begin(); ?> | ||
14 | + | ||
15 | + <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> | ||
16 | + | ||
17 | + <?= $form->field($model, 'name2')->textInput(['maxlength' => true]) ?> | ||
18 | + | ||
19 | + <div class="form-group"> | ||
20 | + <?= Html::submitButton($model->isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | ||
21 | + </div> | ||
22 | + | ||
23 | + <?php ActiveForm::end(); ?> | ||
24 | + | ||
25 | +</div> |
common/modules/product/views/product-variant-type/_search.php
0 โ 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Html; | ||
4 | +use yii\widgets\ActiveForm; | ||
5 | + | ||
6 | +/* @var $this yii\web\View */ | ||
7 | +/* @var $model common\modules\product\models\ProductVariantTypeSearch */ | ||
8 | +/* @var $form yii\widgets\ActiveForm */ | ||
9 | +?> | ||
10 | + | ||
11 | +<div class="product-variant-type-search"> | ||
12 | + | ||
13 | + <?php $form = ActiveForm::begin([ | ||
14 | + 'action' => ['index'], | ||
15 | + 'method' => 'get', | ||
16 | + ]); ?> | ||
17 | + | ||
18 | + <?= $form->field($model, 'product_variant_type_id') ?> | ||
19 | + | ||
20 | + <?= $form->field($model, 'name') ?> | ||
21 | + | ||
22 | + <?= $form->field($model, 'name2') ?> | ||
23 | + | ||
24 | + <div class="form-group"> | ||
25 | + <?= Html::submitButton(Yii::t('product', 'Search'), ['class' => 'btn btn-primary']) ?> | ||
26 | + <?= Html::resetButton(Yii::t('product', 'Reset'), ['class' => 'btn btn-default']) ?> | ||
27 | + </div> | ||
28 | + | ||
29 | + <?php ActiveForm::end(); ?> | ||
30 | + | ||
31 | +</div> |
common/modules/product/views/product-variant-type/create.php
0 โ 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Html; | ||
4 | + | ||
5 | + | ||
6 | +/* @var $this yii\web\View */ | ||
7 | +/* @var $model common\modules\product\models\ProductVariantType */ | ||
8 | + | ||
9 | +$this->title = Yii::t('product', 'Create Product Variant Type'); | ||
10 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Product Variant Types'), 'url' => ['index']]; | ||
11 | +$this->params['breadcrumbs'][] = $this->title; | ||
12 | +?> | ||
13 | +<div class="product-variant-type-create"> | ||
14 | + | ||
15 | + <h1><?= Html::encode($this->title) ?></h1> | ||
16 | + | ||
17 | + <?= $this->render('_form', [ | ||
18 | + 'model' => $model, | ||
19 | + ]) ?> | ||
20 | + | ||
21 | +</div> |
common/modules/product/views/product-variant-type/index.php
0 โ 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Html; | ||
4 | +use yii\grid\GridView; | ||
5 | + | ||
6 | +/* @var $this yii\web\View */ | ||
7 | +/* @var $searchModel common\modules\product\models\ProductVariantTypeSearch */ | ||
8 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | ||
9 | + | ||
10 | +$this->title = Yii::t('product', 'Product Variant Types'); | ||
11 | +$this->params['breadcrumbs'][] = $this->title; | ||
12 | +?> | ||
13 | +<div class="product-variant-type-index"> | ||
14 | + | ||
15 | + <h1><?= Html::encode($this->title) ?></h1> | ||
16 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | ||
17 | + | ||
18 | + <p> | ||
19 | + <?= Html::a(Yii::t('product', 'Create Product Variant Type'), ['create'], ['class' => 'btn btn-success']) ?> | ||
20 | + </p> | ||
21 | + <?= GridView::widget([ | ||
22 | + 'dataProvider' => $dataProvider, | ||
23 | + 'filterModel' => $searchModel, | ||
24 | + 'columns' => [ | ||
25 | + ['class' => 'yii\grid\SerialColumn'], | ||
26 | + 'name', | ||
27 | + 'name2', | ||
28 | + | ||
29 | + ['class' => 'yii\grid\ActionColumn'], | ||
30 | + ], | ||
31 | + ]); ?> | ||
32 | +</div> |
common/modules/product/views/product-variant-type/update.php
0 โ 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Html; | ||
4 | + | ||
5 | +/* @var $this yii\web\View */ | ||
6 | +/* @var $model common\modules\product\models\ProductVariantType */ | ||
7 | + | ||
8 | +$this->title = Yii::t('product', 'Update {modelClass}: ', [ | ||
9 | + 'modelClass' => 'Product Variant Type', | ||
10 | +]) . $model->name; | ||
11 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Product Variant Types'), 'url' => ['index']]; | ||
12 | +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->product_variant_type_id]]; | ||
13 | +$this->params['breadcrumbs'][] = Yii::t('product', 'Update'); | ||
14 | +?> | ||
15 | +<div class="product-variant-type-update"> | ||
16 | + | ||
17 | + <h1><?= Html::encode($this->title) ?></h1> | ||
18 | + | ||
19 | + <?= $this->render('_form', [ | ||
20 | + 'model' => $model, | ||
21 | + ]) ?> | ||
22 | + | ||
23 | +</div> |
common/modules/product/views/product-variant-type/view.php
0 โ 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Html; | ||
4 | +use yii\widgets\DetailView; | ||
5 | + | ||
6 | +/* @var $this yii\web\View */ | ||
7 | +/* @var $model common\modules\product\models\ProductVariantType */ | ||
8 | + | ||
9 | +$this->title = $model->name; | ||
10 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Product Variant Types'), 'url' => ['index']]; | ||
11 | +$this->params['breadcrumbs'][] = $this->title; | ||
12 | +?> | ||
13 | +<div class="product-variant-type-view"> | ||
14 | + | ||
15 | + <h1><?= Html::encode($this->title) ?></h1> | ||
16 | + | ||
17 | + <p> | ||
18 | + <?= Html::a(Yii::t('product', 'Update'), ['update', 'id' => $model->product_variant_type_id], ['class' => 'btn btn-primary']) ?> | ||
19 | + <?= Html::a(Yii::t('product', 'Delete'), ['delete', 'id' => $model->product_variant_type_id], [ | ||
20 | + 'class' => 'btn btn-danger', | ||
21 | + 'data' => [ | ||
22 | + 'confirm' => Yii::t('product', 'Are you sure you want to delete this item?'), | ||
23 | + 'method' => 'post', | ||
24 | + ], | ||
25 | + ]) ?> | ||
26 | + </p> | ||
27 | + | ||
28 | + <?= DetailView::widget([ | ||
29 | + 'model' => $model, | ||
30 | + 'attributes' => [ | ||
31 | + 'product_variant_type_id', | ||
32 | + 'name', | ||
33 | + 'name2', | ||
34 | + ], | ||
35 | + ]) ?> | ||
36 | + | ||
37 | +</div> |