550eac02
Administrator
second
|
1
2
3
4
|
<?php
namespace frontend\controllers;
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
5
6
7
8
|
use common\modules\product\Filter;
use common\modules\product\helpers\ProductHelper;
use common\modules\rubrication\models\TaxOptionSearch;
use frontend\models\ProductFrontendSearch;
|
550eac02
Administrator
second
|
9
|
use Yii;
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
use common\modules\product\models\Brand;
use common\modules\product\models\BrandSearch;
use common\modules\product\models\Category;
use common\modules\product\models\CategorySearch;
use common\modules\product\models\Product;
use common\modules\product\models\ProductCategory;
use common\modules\product\models\ProductOption;
use common\modules\product\models\ProductSearch;
use common\modules\product\models\ProductVariant;
use common\modules\rubrication\models\TaxGroup;
use common\modules\rubrication\models\TaxOption;
use common\modules\rubrication\models\TaxValueString;
use yii\data\ActiveDataProvider;
use yii\data\Pagination;
use yii\data\Sort;
use yii\db\ActiveQuery;
|
1b898c16
Administrator
20.07.16
|
26
|
use yii\helpers\ArrayHelper;
|
550eac02
Administrator
second
|
27
28
|
use yii\web\HttpException;
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
29
|
class CatalogController extends \yii\web\Controller
|
550eac02
Administrator
second
|
30
|
{
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
31
32
33
|
public function actionSearch() {
// @todo
}
|
550eac02
Administrator
second
|
34
|
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
35
|
public function actionCategory()
|
550eac02
Administrator
second
|
36
|
{
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
37
38
|
/** @var Category $category */
$category = Yii::$app->request->get('category');
|
1b898c16
Administrator
20.07.16
|
39
|
$filter = Yii::$app->request->get('filters', []);
|
466144f8
Administrator
20.07.16
|
40
|
$filter_check = $filter;
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
41
42
|
if (empty($category->category_id) && empty($word)) {
|
8724ec1f
Karnovsky A
-
|
43
44
45
|
return $this->render(
'catalog'
);
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
46
47
|
}
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
48
|
|
0f852b51
Administrator
29.06.16
|
49
|
$params = [];
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
50
|
|
1b898c16
Administrator
20.07.16
|
51
52
|
$optionsList = ArrayHelper::getColumn(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(),'alias');
|
0f852b51
Administrator
29.06.16
|
53
|
if ( !empty($filter['brands']) ) {
|
466144f8
Administrator
20.07.16
|
54
|
unset($filter_check['brands']);
|
0f852b51
Administrator
29.06.16
|
55
56
57
58
|
$brands = Brand::find()->select('brand_id')->where(['in', 'alias', $filter['brands']])->all();
$params['brands'] = [];
foreach ($brands as $brand) {
$params['brands'][] = $brand->brand_id;
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
59
|
}
|
0f852b51
Administrator
29.06.16
|
60
|
}
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
61
|
|
0f852b51
Administrator
29.06.16
|
62
|
if ( !empty($filter['special']) ) {
|
466144f8
Administrator
20.07.16
|
63
|
unset($filter_check['special']);
|
0f852b51
Administrator
29.06.16
|
64
65
66
67
68
69
70
71
72
73
74
75
76
|
if (!is_array($filter['special'])) {
$filter['special'] = [$filter['special']];
}
if (in_array('new', $filter['special'])) {
$params['special']['is_new'] = true;
}
if (in_array('top', $filter['special'])) {
$params['special']['is_top'] = true;
}
if (in_array('promo', $filter['special'])) {
$params['special']['akciya'] = true;
}
}
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
77
|
|
1b898c16
Administrator
20.07.16
|
78
|
|
ac8ab861
Administrator
20.07.16
|
79
|
if ( !empty($filter['prices']) ) {
|
466144f8
Administrator
20.07.16
|
80
|
unset($filter_check['prices']);
|
ac8ab861
Administrator
20.07.16
|
81
82
83
84
85
|
$params['prices'] = $filter['prices'];
}
|
1b898c16
Administrator
20.07.16
|
86
87
88
|
foreach($optionsList as $optionList){
if(isset($filter[$optionList])){
|
466144f8
Administrator
20.07.16
|
89
|
unset($filter_check[$optionList]);
|
1b898c16
Administrator
20.07.16
|
90
91
92
|
$params[$optionList] = $filter[$optionList];
}
|
8724ec1f
Karnovsky A
-
|
93
|
}
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
94
|
|
466144f8
Administrator
20.07.16
|
95
96
97
98
|
if(!empty($filter_check)){
$filter = array_diff_key($filter,$filter_check);
Yii::$app->response->redirect(['catalog/category', 'category' => $category, 'filters' =>$filter],301);
}
|
1b898c16
Administrator
20.07.16
|
99
|
|
0f852b51
Administrator
29.06.16
|
100
|
$productModel = new ProductFrontendSearch();
|
1b898c16
Administrator
20.07.16
|
101
|
//$productQuery = $productModel->getSearchQuery($category, $params);
|
0f852b51
Administrator
29.06.16
|
102
|
$productProvider = $productModel->search($category, $params);
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
103
|
|
0f852b51
Administrator
29.06.16
|
104
105
|
$brandModel = new BrandSearch();
$brands = $brandModel->getBrands($category, $params)->all();
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
106
|
|
0f852b51
Administrator
29.06.16
|
107
108
|
$optionsQuery = $productModel->optionsForCategory($category, $params);
$groups = [];
|
1b898c16
Administrator
20.07.16
|
109
110
|
|
0f852b51
Administrator
29.06.16
|
111
112
113
114
|
foreach ($optionsQuery->all() as $option) {
if (!isset($groups[$option->tax_group_id])) {
$groups[$option->tax_group_id] = $option->taxGroup;
$groups[$option->tax_group_id]->_options = [];
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
115
|
}
|
0f852b51
Administrator
29.06.16
|
116
117
118
119
120
121
|
$groups[$option->tax_group_id]->_options[] = $option;
}
foreach($groups as $i => $group) {
if (empty($group->_options))
unset($groups[$i]);
}
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
122
|
|
0f852b51
Administrator
29.06.16
|
123
|
$priceLimits = $productModel->priceLimits($category, $params);
|
e608c5f7
Yarik
Comment added
|
124
125
126
127
|
/*
* Greedy search for comments and rating
*/
|
17ca60dd
Yarik
Added comments to...
|
128
129
|
$query = $productProvider->query;
$query->with(['comments', 'averageRating']);
|
e608c5f7
Yarik
Comment added
|
130
131
132
|
/*
* End of greedy search for rating and comments
*/
|
0f852b51
Administrator
29.06.16
|
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
return $this->render(
'products',
[
'category' => $category,
'brandModel' => $brandModel,
'brands' => $brands,
'filter' => $filter,
'params' => $params,
'productModel' => $productModel,
'productProvider' => $productProvider,
'groups' => $groups,
'priceLimits' => $priceLimits,
]
);
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
148
|
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
149
150
151
152
|
}
public function actionProduct()
{
|
ccc7a9d3
Karnovsky A
Karnovsky 12052016
|
153
|
/** @var Product $product */
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
154
155
|
$product = Yii::$app->request->get('product');
|
3147aab1
Karnovsky A
Fix search with s...
|
156
157
158
159
|
if(!$product->enabledVariant) {
throw new HttpException(404, 'Товар не найден');
}
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
160
161
162
163
|
ProductHelper::addLastProsucts($product->product_id);
return $this->render('product', [
'product' => $product,
|
c7852657
Karnovsky A
-
|
164
|
'category' => $product->category,
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
165
|
]);
|
550eac02
Administrator
second
|
166
|
}
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
167
168
|
public function actionBrands()
|
550eac02
Administrator
second
|
169
|
{
|
38828295
Karnovsky A
-
|
170
171
172
173
174
175
176
177
178
179
|
$dataProvider = new ActiveDataProvider([
'query' => Brand::find()->joinWith('brandName')->orderBy('brand_name.value'),
'pagination' => [
'pageSize' => -1,
]
]);
return $this->render('brands', [
'dataProvider' => $dataProvider,
]);
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
180
181
|
}
|
868680ca
Karnovsky A
-
|
182
|
public function actionBrand($brand)
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
183
|
{
|
ac8ab861
Administrator
20.07.16
|
184
|
$brand = BrandSearch::findByAlias($brand);
|
868680ca
Karnovsky A
-
|
185
186
|
$params = [
|
ac8ab861
Administrator
20.07.16
|
187
|
'brands' => $brand->brand_id,
|
868680ca
Karnovsky A
-
|
188
189
|
];
|
868680ca
Karnovsky A
-
|
190
191
192
193
194
195
196
197
198
199
|
$productModel = new ProductFrontendSearch();
$productProvider = $productModel->search(null, $params);
$priceLimits = $productModel->priceLimits(null, $params);
return $this->render('brand', [
'productModel' => $productModel,
'productProvider' => $productProvider,
'brand' => $brand,
'priceLimits' => $priceLimits,
|
868680ca
Karnovsky A
-
|
200
|
]);
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
201
202
203
|
}
}
|