85261b14
Karnovsky A
not fixed commite
|
1
2
3
4
|
<?php
namespace frontend\controllers;
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
5
|
use common\modules\product\Filter;
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
6
|
use common\modules\product\helpers\ProductHelper;
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
7
8
9
|
use common\modules\rubrication\models\TaxOptionSearch;
use frontend\models\ProductFrontendSearch;
use Yii;
|
b519af22
Karnovsky A
Base-product func...
|
10
|
use common\modules\product\models\Brand;
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
11
|
use common\modules\product\models\BrandSearch;
|
85261b14
Karnovsky A
not fixed commite
|
12
13
14
|
use common\modules\product\models\Category;
use common\modules\product\models\CategorySearch;
use common\modules\product\models\Product;
|
b519af22
Karnovsky A
Base-product func...
|
15
|
use common\modules\product\models\ProductCategory;
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
16
|
use common\modules\product\models\ProductOption;
|
b519af22
Karnovsky A
Base-product func...
|
17
18
|
use common\modules\product\models\ProductSearch;
use common\modules\product\models\ProductVariant;
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
19
20
|
use common\modules\rubrication\models\TaxGroup;
use common\modules\rubrication\models\TaxOption;
|
14eadb86
Karnovsky A
Eager loading for...
|
21
|
use common\modules\rubrication\models\TaxValueString;
|
b519af22
Karnovsky A
Base-product func...
|
22
23
24
25
|
use yii\data\ActiveDataProvider;
use yii\data\Pagination;
use yii\data\Sort;
use yii\db\ActiveQuery;
|
85261b14
Karnovsky A
not fixed commite
|
26
27
28
29
|
use yii\web\HttpException;
class CatalogController extends \yii\web\Controller
{
|
020c69f5
Karnovsky A
Base-product#5 fu...
|
30
|
public function actionSearch() {
|
5672b289
Karnovsky A
--
|
31
|
// @todo
|
020c69f5
Karnovsky A
Base-product#5 fu...
|
32
33
|
}
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
34
|
public function actionCategory()
|
85261b14
Karnovsky A
not fixed commite
|
35
|
{
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
36
37
38
|
/** @var Category $category */
$category = Yii::$app->request->get('category');
$filter = Yii::$app->request->get('filter', []);
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
39
|
$word = trim(Yii::$app->request->get('word', ''));
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
40
|
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
41
|
if (empty($category->category_id) && empty($word)) {
|
b519af22
Karnovsky A
Base-product func...
|
42
43
|
throw new HttpException(404 ,'Page not found');
}
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
$last_products = ProductHelper::getLastProducts(true);
if (!empty($word)) {
$params = [];
$params['keywords'] = explode(' ', preg_replace("|[\s,.!:&?~();-]|i", " ", $word));
foreach($params['keywords'] as $i => &$keyword) {
$keyword = trim($keyword);
if (empty($keyword)) {
unset($params['keywords'][$i]);
}
}
$productModel = new ProductFrontendSearch();
$productProvider = $productModel->search($category, $params);
$categoriesQuery = Category::find()
->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.category_id = '. Category::tableName() .'.category_id')
->innerJoin(Product::tableName(), Product::tableName() .'.product_id = '. ProductCategory::tableName() .'.product_id');
foreach ($params['keywords'] as $keyword) {
$categoriesQuery->andWhere(['ilike', 'product.name', $keyword]);
}
$categories = $categoriesQuery->all();
return $this->render(
'search',
[
'keywords' => $params['keywords'],
'category' => $category,
'productModel' => $productModel,
'productProvider' => $productProvider,
'last_products' => $last_products,
'categories' => $categories,
]
);
} elseif ($category->depth < 2) {
|
85261b14
Karnovsky A
not fixed commite
|
82
83
84
|
return $this->render(
'categories',
[
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
85
86
|
'category' => $category,
'last_products' => $last_products,
|
85261b14
Karnovsky A
not fixed commite
|
87
88
89
|
]
);
} else {
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
90
|
$params = [];
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
91
|
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
92
93
94
95
96
|
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;
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
97
|
}
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
98
99
100
101
102
103
104
105
106
107
108
109
|
}
if ( !empty($filter['options']) ) {
$params['options'] = $filter['options'];
/*$optionQuery = TaxOption::find();
$optionQuery->select('tax_option_id');
$optionQuery->innerJoinWith('group');
foreach ($filter['options'] as $option_key => $option_values) {
$optionQuery->orWhere([
'tax_group_id' => $option_key,
'alias' => $filter['options']
]);
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
110
|
}
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
111
112
113
114
115
|
$options = ->where(['in', 'alias', $filter['options']])->all();
$params['options'] = [];
foreach ($options as $option) {
$params['options'][] = $option->tax_option_id;
}*/
|
b15c889e
Karnovsky A
Base-product#2 fu...
|
116
|
}
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
117
|
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
118
119
|
if ( !empty($filter['prices']) ) {
$params['prices'] = $filter['prices'];
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
120
|
}
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
$productModel = new ProductFrontendSearch();
$productProvider = $productModel->search($category, $params);
$brandModel = new BrandSearch();
$brandProvider = $brandModel->getBrands($category, $params);
$optionsProvider = $productModel->optionsForCategory($category, $params);
$groups = [];
foreach ($optionsProvider->models as $option) {
if (!isset($groups[$option->tax_group_id])) {
$groups[$option->tax_group_id] = $option->taxGroup;
$groups[$option->tax_group_id]->_options = [];
}
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
135
136
137
138
139
140
141
|
$groups[$option->tax_group_id]->_options[] = $option;
}
foreach($groups as $i => $group) {
if (empty($group->_options))
unset($groups[$i]);
}
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
142
|
$priceLimits = $productModel->priceLimits($category, $params);
|
b519af22
Karnovsky A
Base-product func...
|
143
|
|
85261b14
Karnovsky A
not fixed commite
|
144
145
146
|
return $this->render(
'products',
[
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
147
148
149
150
151
152
153
154
155
|
'category' => $category,
'brandModel' => $brandModel,
'brandProvider' => $brandProvider,
'filter' => $filter,
'productModel' => $productModel,
'productProvider' => $productProvider,
'optionsProvider' => $optionsProvider,
'groups' => $groups,
'priceLimits' => $priceLimits,
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
156
|
'last_products' => $last_products,
|
85261b14
Karnovsky A
not fixed commite
|
157
158
159
160
161
|
]
);
}
}
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
162
|
public function actionProduct()
|
85261b14
Karnovsky A
not fixed commite
|
163
|
{
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
164
165
|
$product = Yii::$app->request->get('product');
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
166
167
168
169
170
171
172
173
174
175
176
177
|
$groups = [];
foreach($product->category->getTaxGroups()->all() as $_group) {
$groups[$_group->tax_group_id] = $_group;
}
foreach ($product->options as $option) {
$groups[$option->tax_group_id]->_options[] = $option;
}
foreach($groups as $i => $group) {
if (empty($group->_options))
unset($groups[$i]);
}
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
178
179
180
|
$last_products = ProductHelper::getLastProducts(true);
ProductHelper::addLastProsucts($product->product_id);
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
181
182
183
|
return $this->render('product', [
'product' => $product,
'properties' => $groups,
|
ad9b9ca9
Karnovsky A
Karnovsky-2904201...
|
184
|
'last_products' => $last_products
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
185
|
]);
|
85261b14
Karnovsky A
not fixed commite
|
186
187
188
189
190
191
192
193
194
195
196
197
198
|
}
public function actionBrands()
{
return 'actionBrands';
}
public function actionBrand($alias)
{
return 'actionBrand:'. $alias;
}
}
|