Commit 00731fef3c07a8c765ce6cda1587277881622f1f
1 parent
8940d2f7
Before vitex test
Showing
4 changed files
with
159 additions
and
62 deletions
Show diff stats
common/modules/product/controllers/ManageController.php
@@ -61,8 +61,17 @@ | @@ -61,8 +61,17 @@ | ||
61 | */ | 61 | */ |
62 | public function actionView($id) | 62 | public function actionView($id) |
63 | { | 63 | { |
64 | + $model = $this->findModel($id); | ||
65 | + $categories = $model->getCategories() | ||
66 | + ->with('lang') | ||
67 | + ->all(); | ||
68 | + $variants = $model->getVariants() | ||
69 | + ->with('lang') | ||
70 | + ->all(); | ||
64 | return $this->render('view', [ | 71 | return $this->render('view', [ |
65 | - 'model' => $this->findModel($id), | 72 | + 'model' => $this->findModel($id), |
73 | + 'categories' => $categories, | ||
74 | + 'variants' => $variants, | ||
66 | ]); | 75 | ]); |
67 | } | 76 | } |
68 | 77 | ||
@@ -257,7 +266,6 @@ | @@ -257,7 +266,6 @@ | ||
257 | 'method' => $model->type, | 266 | 'method' => $model->type, |
258 | 'target' => $target, | 267 | 'target' => $target, |
259 | ]); | 268 | ]); |
260 | - // $model->$method(); | ||
261 | } else { | 269 | } else { |
262 | $model->errors[] = 'File can not be upload or other error'; | 270 | $model->errors[] = 'File can not be upload or other error'; |
263 | } | 271 | } |
@@ -318,12 +326,6 @@ | @@ -318,12 +326,6 @@ | ||
318 | return $this->render('export', [ | 326 | return $this->render('export', [ |
319 | 'model' => $model, | 327 | 'model' => $model, |
320 | ]); | 328 | ]); |
321 | - // $model = new Export(); | ||
322 | - // if(( $file = $model->process(Yii::getAlias('@uploadDir')) )) { | ||
323 | - // return Yii::$app->response->sendFile($file) | ||
324 | - // ->send(); | ||
325 | - // } | ||
326 | - // throw new NotFoundHttpException('Error'); | ||
327 | } | 329 | } |
328 | 330 | ||
329 | /** | 331 | /** |
@@ -337,7 +339,11 @@ | @@ -337,7 +339,11 @@ | ||
337 | */ | 339 | */ |
338 | protected function findModel($id) | 340 | protected function findModel($id) |
339 | { | 341 | { |
340 | - if(( $model = Product::findOne($id) ) !== NULL) { | 342 | + if(( $model = Product::find() |
343 | + ->where([ 'product_id' => $id ]) | ||
344 | + ->with('lang') | ||
345 | + ->one() ) !== NULL | ||
346 | + ) { | ||
341 | return $model; | 347 | return $model; |
342 | } else { | 348 | } else { |
343 | throw new NotFoundHttpException('The requested page does not exist.'); | 349 | throw new NotFoundHttpException('The requested page does not exist.'); |
common/modules/product/models/ProductSearch.php
@@ -17,7 +17,9 @@ | @@ -17,7 +17,9 @@ | ||
17 | 17 | ||
18 | public $category_id; | 18 | public $category_id; |
19 | 19 | ||
20 | - public $variant_sku; | 20 | + public $product_name; |
21 | + | ||
22 | + public $variant_count; | ||
21 | 23 | ||
22 | public function behaviors() | 24 | public function behaviors() |
23 | { | 25 | { |
@@ -35,7 +37,9 @@ | @@ -35,7 +37,9 @@ | ||
35 | { | 37 | { |
36 | return [ | 38 | return [ |
37 | [ | 39 | [ |
38 | - [ 'variant_sku' ], | 40 | + [ |
41 | + 'product_name', | ||
42 | + ], | ||
39 | 'safe', | 43 | 'safe', |
40 | ], | 44 | ], |
41 | [ | 45 | [ |
@@ -43,7 +47,6 @@ | @@ -43,7 +47,6 @@ | ||
43 | 'brand_id', | 47 | 'brand_id', |
44 | 'product_id', | 48 | 'product_id', |
45 | 'category_id', | 49 | 'category_id', |
46 | - 'brand_id', | ||
47 | ], | 50 | ], |
48 | 'integer', | 51 | 'integer', |
49 | ], | 52 | ], |
@@ -58,6 +61,18 @@ | @@ -58,6 +61,18 @@ | ||
58 | ]; | 61 | ]; |
59 | } | 62 | } |
60 | 63 | ||
64 | + public function attributeLabels() | ||
65 | + { | ||
66 | + $labels = parent::attributeLabels(); | ||
67 | + $new_labels = [ | ||
68 | + 'category_id' => 'Category ID', | ||
69 | + 'brand_id' => 'Brand ID', | ||
70 | + 'product_name' => 'Product name', | ||
71 | + 'variant_count' => 'Variant count', | ||
72 | + ]; | ||
73 | + return array_merge($labels, $new_labels); | ||
74 | + } | ||
75 | + | ||
61 | /** | 76 | /** |
62 | * @inheritdoc | 77 | * @inheritdoc |
63 | */ | 78 | */ |
@@ -79,9 +94,14 @@ | @@ -79,9 +94,14 @@ | ||
79 | 94 | ||
80 | $query = Product::find(); | 95 | $query = Product::find(); |
81 | 96 | ||
97 | + $query->select([ | ||
98 | + 'product.*', | ||
99 | + 'COUNT(product_variant.product_variant_id) as count', | ||
100 | + ]); | ||
101 | + | ||
82 | $query->joinWith([ | 102 | $query->joinWith([ |
83 | 'categories', | 103 | 'categories', |
84 | - /*'variant'*/ | 104 | + 'lang', |
85 | ]) | 105 | ]) |
86 | ->joinWith([ | 106 | ->joinWith([ |
87 | 'brand' => function($query) { | 107 | 'brand' => function($query) { |
@@ -90,9 +110,14 @@ | @@ -90,9 +110,14 @@ | ||
90 | */ | 110 | */ |
91 | $query->joinWith('lang'); | 111 | $query->joinWith('lang'); |
92 | }, | 112 | }, |
93 | - ]); | 113 | + ]) |
114 | + ->joinWith('variants'); | ||
94 | 115 | ||
95 | - $query->groupBy([ 'product.product_id', 'brand_lang.name' ]); | 116 | + $query->groupBy([ |
117 | + 'product.product_id', | ||
118 | + 'brand_lang.name', | ||
119 | + 'product_lang.name', | ||
120 | + ]); | ||
96 | 121 | ||
97 | $dataProvider = new ActiveDataProvider([ | 122 | $dataProvider = new ActiveDataProvider([ |
98 | 'query' => $query, | 123 | 'query' => $query, |
@@ -104,11 +129,19 @@ | @@ -104,11 +129,19 @@ | ||
104 | 129 | ||
105 | $dataProvider->setSort([ | 130 | $dataProvider->setSort([ |
106 | 'attributes' => [ | 131 | 'attributes' => [ |
107 | - 'brand_id' => [ | 132 | + 'product_id', |
133 | + 'product_name' => [ | ||
134 | + 'asc' => [ 'product_lang.name' => SORT_ASC ], | ||
135 | + 'desc' => [ 'product_lang.name' => SORT_DESC ], | ||
136 | + ], | ||
137 | + 'brand_id' => [ | ||
108 | 'asc' => [ 'brand_lang.name' => SORT_ASC ], | 138 | 'asc' => [ 'brand_lang.name' => SORT_ASC ], |
109 | 'desc' => [ 'brand_lang.name' => SORT_DESC ], | 139 | 'desc' => [ 'brand_lang.name' => SORT_DESC ], |
110 | 'default' => SORT_DESC, | 140 | 'default' => SORT_DESC, |
111 | - 'label' => 'Brand name', | 141 | + ], |
142 | + 'variant_count' => [ | ||
143 | + 'asc' => [ 'count' => SORT_ASC ], | ||
144 | + 'desc' => [ 'count' => SORT_DESC ], | ||
112 | ], | 145 | ], |
113 | ], | 146 | ], |
114 | ]); | 147 | ]); |
@@ -133,9 +166,11 @@ | @@ -133,9 +166,11 @@ | ||
133 | 'product.product_id' => $this->product_id, | 166 | 'product.product_id' => $this->product_id, |
134 | 'product_category.category_id' => $this->category_id, | 167 | 'product_category.category_id' => $this->category_id, |
135 | ]); | 168 | ]); |
136 | - | ||
137 | - // $query->andFilterWhere(['ilike', 'brand.name', $this->brand_name]); | ||
138 | - // $query->andFilterWhere(['ilike', 'product_variant.sku', $this->variant_sku]); | 169 | + $query->andFilterWhere([ |
170 | + 'like', | ||
171 | + 'product_lang.name', | ||
172 | + $this->product_name, | ||
173 | + ]); | ||
139 | 174 | ||
140 | return $dataProvider; | 175 | return $dataProvider; |
141 | } | 176 | } |
common/modules/product/views/manage/index.php
@@ -3,16 +3,20 @@ | @@ -3,16 +3,20 @@ | ||
3 | use common\modules\product\models\Brand; | 3 | use common\modules\product\models\Brand; |
4 | use common\modules\product\models\Category; | 4 | use common\modules\product\models\Category; |
5 | use common\modules\product\models\Product; | 5 | use common\modules\product\models\Product; |
6 | + use common\modules\product\models\ProductSearch; | ||
7 | + use yii\data\ActiveDataProvider; | ||
6 | use yii\helpers\Html; | 8 | use yii\helpers\Html; |
7 | use yii\grid\GridView; | 9 | use yii\grid\GridView; |
8 | use kartik\select2\Select2; | 10 | use kartik\select2\Select2; |
9 | use common\components\artboxtree\ArtboxTreeHelper; | 11 | use common\components\artboxtree\ArtboxTreeHelper; |
10 | use common\modules\product\helpers\ProductHelper; | 12 | use common\modules\product\helpers\ProductHelper; |
13 | + use yii\web\View; | ||
11 | 14 | ||
12 | - /* @var $this yii\web\View */ | ||
13 | - /* @var $searchModel common\modules\product\models\ProductSearch */ | ||
14 | - /* @var $dataProvider yii\data\ActiveDataProvider */ | ||
15 | - | 15 | + /** |
16 | + * @var View $this | ||
17 | + * @var ProductSearch $searchModel | ||
18 | + * @var ActiveDataProvider $dataProvider | ||
19 | + */ | ||
16 | $this->title = Yii::t('product', 'Products'); | 20 | $this->title = Yii::t('product', 'Products'); |
17 | $this->params[ 'breadcrumbs' ][] = $this->title; | 21 | $this->params[ 'breadcrumbs' ][] = $this->title; |
18 | ?> | 22 | ?> |
@@ -29,13 +33,25 @@ | @@ -29,13 +33,25 @@ | ||
29 | 'columns' => [ | 33 | 'columns' => [ |
30 | 'product_id', | 34 | 'product_id', |
31 | [ | 35 | [ |
32 | - 'label' => Yii::t('product', 'Brand'), | 36 | + 'attribute' => 'product_name', |
37 | + 'value' => 'lang.name', | ||
38 | + ], | ||
39 | + [ | ||
40 | + 'label' => Yii::t('product', 'Brand'), | ||
33 | 'attribute' => 'brand_id', | 41 | 'attribute' => 'brand_id', |
34 | - 'value' => 'brand.lang.name', | ||
35 | - 'filter' => Select2::widget([ | 42 | + 'value' => 'brand.lang.name', |
43 | + 'filter' => Select2::widget([ | ||
36 | 'model' => $searchModel, | 44 | 'model' => $searchModel, |
37 | 'attribute' => 'brand_id', | 45 | 'attribute' => 'brand_id', |
38 | - 'data' => Brand::find()->joinWith('lang')->select(['brand_lang.name', 'brand.brand_id'])->asArray()->indexBy('brand_id')->column(), | 46 | + 'data' => Brand::find() |
47 | + ->joinWith('lang') | ||
48 | + ->select([ | ||
49 | + 'brand_lang.name', | ||
50 | + 'brand.brand_id', | ||
51 | + ]) | ||
52 | + ->asArray() | ||
53 | + ->indexBy('brand_id') | ||
54 | + ->column(), | ||
39 | 'language' => 'ru', | 55 | 'language' => 'ru', |
40 | 'options' => [ | 56 | 'options' => [ |
41 | 'placeholder' => Yii::t('product', 'Select brand'), | 57 | 'placeholder' => Yii::t('product', 'Select brand'), |
@@ -54,7 +70,9 @@ | @@ -54,7 +70,9 @@ | ||
54 | * @var Product $model | 70 | * @var Product $model |
55 | */ | 71 | */ |
56 | $categories = []; | 72 | $categories = []; |
57 | - foreach($model->getCategories()->with('lang')->all() as $category) { | 73 | + foreach($model->getCategories() |
74 | + ->with('lang') | ||
75 | + ->all() as $category) { | ||
58 | /** | 76 | /** |
59 | * @var Category $category | 77 | * @var Category $category |
60 | */ | 78 | */ |
@@ -76,18 +94,15 @@ | @@ -76,18 +94,15 @@ | ||
76 | ], | 94 | ], |
77 | ]), | 95 | ]), |
78 | ], | 96 | ], |
79 | - // [ | ||
80 | - // 'label' => Yii::t('product', 'SKU'), | ||
81 | - // 'attribute' => 'variant_sku', | ||
82 | - // 'value' => 'variant.sku', | ||
83 | - // ], | ||
84 | - // 'variant.price', | ||
85 | - // 'variant.price_old', | ||
86 | - // [ | ||
87 | - // 'label' => Yii::t('product', 'Stock'), | ||
88 | - // 'attribute' => 'variant_stock', | ||
89 | - // 'value' => 'variant.stock_caption', | ||
90 | - // ], | 97 | + [ |
98 | + 'attribute' => 'variant_count', | ||
99 | + 'value' => function($model) { | ||
100 | + /** | ||
101 | + * @var Product $model | ||
102 | + */ | ||
103 | + return count($model->variants); | ||
104 | + }, | ||
105 | + ], | ||
91 | [ | 106 | [ |
92 | 'class' => 'yii\grid\ActionColumn', | 107 | 'class' => 'yii\grid\ActionColumn', |
93 | 'template' => '{items} {view} |{is_top} {is_new} {akciya} | {update} {delete}', | 108 | 'template' => '{items} {view} |{is_top} {is_new} {akciya} | {update} {delete}', |
@@ -158,6 +173,8 @@ | @@ -158,6 +173,8 @@ | ||
158 | 'id' => $model->product_id, | 173 | 'id' => $model->product_id, |
159 | ]); | 174 | ]); |
160 | break; | 175 | break; |
176 | + default: | ||
177 | + return ''; | ||
161 | } | 178 | } |
162 | }, | 179 | }, |
163 | ], | 180 | ], |
common/modules/product/views/manage/view.php
1 | <?php | 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\Product */ | ||
8 | - | ||
9 | -$this->title = $model->product_id; | ||
10 | -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Products'), 'url' => ['index']]; | ||
11 | -$this->params['breadcrumbs'][] = $this->title; | 2 | + |
3 | + use common\modules\product\models\Category; | ||
4 | + use common\modules\product\models\Product; | ||
5 | + use yii\helpers\ArrayHelper; | ||
6 | + use yii\helpers\Html; | ||
7 | + use yii\web\View; | ||
8 | + use yii\widgets\DetailView; | ||
9 | + | ||
10 | + /** | ||
11 | + * @var View $this | ||
12 | + * @var Product $model | ||
13 | + * @var Category[] $categories | ||
14 | + */ | ||
15 | + | ||
16 | + $this->title = $model->lang->name; | ||
17 | + $this->params[ 'breadcrumbs' ][] = [ | ||
18 | + 'label' => Yii::t('product', 'Products'), | ||
19 | + 'url' => [ 'index' ], | ||
20 | + ]; | ||
21 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
12 | ?> | 22 | ?> |
13 | <div class="product-view"> | 23 | <div class="product-view"> |
14 | - | 24 | + |
15 | <h1><?= Html::encode($this->title) ?></h1> | 25 | <h1><?= Html::encode($this->title) ?></h1> |
16 | - | 26 | + |
17 | <p> | 27 | <p> |
18 | - <?= Html::a(Yii::t('product', 'Update'), ['update', 'id' => $model->product_id], ['class' => 'btn btn-primary']) ?> | ||
19 | - <?= Html::a(Yii::t('product', 'Delete'), ['delete', 'id' => $model->product_id], [ | 28 | + <?= Html::a(Yii::t('product', 'Update'), [ |
29 | + 'update', | ||
30 | + 'id' => $model->product_id, | ||
31 | + ], [ 'class' => 'btn btn-primary' ]) ?> | ||
32 | + <?= Html::a(Yii::t('product', 'Delete'), [ | ||
33 | + 'delete', | ||
34 | + 'id' => $model->product_id, | ||
35 | + ], [ | ||
20 | 'class' => 'btn btn-danger', | 36 | 'class' => 'btn btn-danger', |
21 | - 'data' => [ | 37 | + 'data' => [ |
22 | 'confirm' => Yii::t('product', 'Are you sure you want to delete this item?'), | 38 | 'confirm' => Yii::t('product', 'Are you sure you want to delete this item?'), |
23 | - 'method' => 'post', | 39 | + 'method' => 'post', |
24 | ], | 40 | ], |
25 | ]) ?> | 41 | ]) ?> |
26 | </p> | 42 | </p> |
27 | - | 43 | + |
28 | <?= DetailView::widget([ | 44 | <?= DetailView::widget([ |
29 | - 'model' => $model, | 45 | + 'model' => $model, |
30 | 'attributes' => [ | 46 | 'attributes' => [ |
31 | 'product_id', | 47 | 'product_id', |
32 | -// 'brand.name', | ||
33 | -// 'category.name', | ||
34 | - 'image.imageUrl:image' | 48 | + 'brand.lang.name', |
49 | + [ | ||
50 | + 'label' => \Yii::t('app', 'Categories'), | ||
51 | + 'value' => implode('<br>', ArrayHelper::getColumn($categories, 'lang.name')), | ||
52 | + 'format' => 'html', | ||
53 | + ], | ||
54 | + [ | ||
55 | + 'attribute' => 'is_top', | ||
56 | + 'value' => $model->is_top ? Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-ok' ]) : Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-remove' ]), | ||
57 | + 'format' => 'html', | ||
58 | + ], | ||
59 | + [ | ||
60 | + 'attribute' => 'is_new', | ||
61 | + 'value' => $model->is_new ? Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-ok' ]) : Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-remove' ]), | ||
62 | + 'format' => 'html', | ||
63 | + ], | ||
64 | + [ | ||
65 | + 'attribute' => 'akciya', | ||
66 | + 'value' => $model->akciya ? Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-ok' ]) : Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-remove' ]), | ||
67 | + 'format' => 'html', | ||
68 | + ], | ||
69 | + [ | ||
70 | + 'attribute' => 'video', | ||
71 | + 'format' => 'html', | ||
72 | + ], | ||
73 | + 'image.imageUrl:image', | ||
35 | ], | 74 | ], |
36 | ]) ?> | 75 | ]) ?> |
37 | 76 |