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;
|
550eac02
Administrator
second
|
26
27
|
use yii\web\HttpException;
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
28
|
class CatalogController extends \yii\web\Controller
|
550eac02
Administrator
second
|
29
|
{
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
30
31
32
|
public function actionSearch() {
// @todo
}
|
550eac02
Administrator
second
|
33
|
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
34
|
public function actionCategory()
|
550eac02
Administrator
second
|
35
|
{
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
36
37
38
|
/** @var Category $category */
$category = Yii::$app->request->get('category');
$filter = Yii::$app->request->get('filter', []);
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
39
40
|
if (empty($category->category_id) && empty($word)) {
|
8724ec1f
Karnovsky A
-
|
41
42
43
|
return $this->render(
'catalog'
);
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
44
45
|
}
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
46
|
|
0f852b51
Administrator
29.06.16
|
47
|
$params = [];
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
48
|
|
0f852b51
Administrator
29.06.16
|
49
50
51
52
53
|
if ( !empty($filter['brands']) ) {
$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
|
54
|
}
|
0f852b51
Administrator
29.06.16
|
55
|
}
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
56
|
|
0f852b51
Administrator
29.06.16
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
if ( !empty($filter['special']) ) {
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
|
71
|
|
0f852b51
Administrator
29.06.16
|
72
73
|
if ( !empty($filter['options']) ) {
$params['options'] = $filter['options'];
|
8724ec1f
Karnovsky A
-
|
74
|
}
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
75
|
|
0f852b51
Administrator
29.06.16
|
76
77
78
|
if ( !empty($filter['prices']) ) {
$params['prices'] = $filter['prices'];
}
|
e2651dcd
Karnovsky A
Special-product-f...
|
79
|
|
0f852b51
Administrator
29.06.16
|
80
81
82
|
$productModel = new ProductFrontendSearch();
$productQuery = $productModel->getSearchQuery($category, $params);
$productProvider = $productModel->search($category, $params);
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
83
|
|
0f852b51
Administrator
29.06.16
|
84
85
|
$brandModel = new BrandSearch();
$brands = $brandModel->getBrands($category, $params)->all();
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
86
|
|
0f852b51
Administrator
29.06.16
|
87
88
89
90
91
92
|
$optionsQuery = $productModel->optionsForCategory($category, $params);
$groups = [];
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
|
93
|
}
|
0f852b51
Administrator
29.06.16
|
94
95
96
97
98
99
|
$groups[$option->tax_group_id]->_options[] = $option;
}
foreach($groups as $i => $group) {
if (empty($group->_options))
unset($groups[$i]);
}
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
100
|
|
0f852b51
Administrator
29.06.16
|
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
$priceLimits = $productModel->priceLimits($category, $params);
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
|
117
|
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
118
119
120
121
|
}
public function actionProduct()
{
|
ccc7a9d3
Karnovsky A
Karnovsky 12052016
|
122
|
/** @var Product $product */
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
123
124
|
$product = Yii::$app->request->get('product');
|
3147aab1
Karnovsky A
Fix search with s...
|
125
126
127
128
|
if(!$product->enabledVariant) {
throw new HttpException(404, 'Товар не найден');
}
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
129
130
131
132
|
ProductHelper::addLastProsucts($product->product_id);
return $this->render('product', [
'product' => $product,
|
c7852657
Karnovsky A
-
|
133
|
'category' => $product->category,
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
134
|
]);
|
550eac02
Administrator
second
|
135
|
}
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
136
137
|
public function actionBrands()
|
550eac02
Administrator
second
|
138
|
{
|
38828295
Karnovsky A
-
|
139
140
141
142
143
144
145
146
147
148
|
$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
|
149
150
|
}
|
868680ca
Karnovsky A
-
|
151
|
public function actionBrand($brand)
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
152
|
{
|
868680ca
Karnovsky A
-
|
153
154
155
156
157
158
159
160
161
162
|
$filter = Yii::$app->request->get('filter', []);
$params = [
'brand_id' => $brand->brand_id,
];
if ( !empty($filter['prices']) ) {
$params['prices'] = $filter['prices'];
}
|
c9d723d7
Karnovsky A
-
|
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
if ( !empty($filter['special']) ) {
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;
}
}
|
868680ca
Karnovsky A
-
|
178
179
180
181
182
183
184
185
186
187
188
189
|
$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,
'filter' => $filter,
]);
|
055ecc3b
Karnovsky A
Karnovsky 11052016
|
190
191
192
|
}
}
|