85261b14
Karnovsky A
not fixed commite
|
1
2
3
4
|
<?php
namespace frontend\controllers;
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
5
6
7
8
|
use common\modules\product\Filter;
use common\modules\rubrication\models\TaxOptionSearch;
use frontend\models\ProductFrontendSearch;
use Yii;
|
b519af22
Karnovsky A
Base-product func...
|
9
|
use common\modules\product\models\Brand;
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
10
|
use common\modules\product\models\BrandSearch;
|
85261b14
Karnovsky A
not fixed commite
|
11
12
13
|
use common\modules\product\models\Category;
use common\modules\product\models\CategorySearch;
use common\modules\product\models\Product;
|
b519af22
Karnovsky A
Base-product func...
|
14
|
use common\modules\product\models\ProductCategory;
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
15
|
use common\modules\product\models\ProductOption;
|
b519af22
Karnovsky A
Base-product func...
|
16
17
|
use common\modules\product\models\ProductSearch;
use common\modules\product\models\ProductVariant;
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
18
19
|
use common\modules\rubrication\models\TaxGroup;
use common\modules\rubrication\models\TaxOption;
|
14eadb86
Karnovsky A
Eager loading for...
|
20
|
use common\modules\rubrication\models\TaxValueString;
|
b519af22
Karnovsky A
Base-product func...
|
21
22
23
24
|
use yii\data\ActiveDataProvider;
use yii\data\Pagination;
use yii\data\Sort;
use yii\db\ActiveQuery;
|
85261b14
Karnovsky A
not fixed commite
|
25
26
27
28
|
use yii\web\HttpException;
class CatalogController extends \yii\web\Controller
{
|
020c69f5
Karnovsky A
Base-product#5 fu...
|
29
30
31
32
|
public function actionSearch() {
}
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
33
|
public function actionCategory()
|
85261b14
Karnovsky A
not fixed commite
|
34
|
{
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
35
36
37
38
|
/** @var Category $category */
$category = Yii::$app->request->get('category');
$filter = Yii::$app->request->get('filter', []);
|
b519af22
Karnovsky A
Base-product func...
|
39
40
41
|
if (empty($category->category_id)) {
throw new HttpException(404 ,'Page not found');
}
|
85261b14
Karnovsky A
not fixed commite
|
42
43
44
45
46
47
48
49
|
if ($category->depth < 2) {
return $this->render(
'categories',
[
'category' => $category
]
);
} else {
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
50
|
$params = [];
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
51
|
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
52
53
54
55
56
|
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...
|
57
|
}
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
58
59
60
61
62
63
64
65
66
67
68
69
|
}
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...
|
70
|
}
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
71
72
73
74
75
|
$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...
|
76
|
}
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
77
|
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
78
79
|
if ( !empty($filter['prices']) ) {
$params['prices'] = $filter['prices'];
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
80
|
}
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
$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...
|
95
96
97
98
99
100
101
|
$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
|
102
|
$priceLimits = $productModel->priceLimits($category, $params);
|
b519af22
Karnovsky A
Base-product func...
|
103
|
|
85261b14
Karnovsky A
not fixed commite
|
104
105
106
|
return $this->render(
'products',
[
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
107
108
109
110
111
112
113
114
115
|
'category' => $category,
'brandModel' => $brandModel,
'brandProvider' => $brandProvider,
'filter' => $filter,
'productModel' => $productModel,
'productProvider' => $productProvider,
'optionsProvider' => $optionsProvider,
'groups' => $groups,
'priceLimits' => $priceLimits,
|
85261b14
Karnovsky A
not fixed commite
|
116
117
118
119
120
|
]
);
}
}
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
121
|
public function actionProduct()
|
85261b14
Karnovsky A
not fixed commite
|
122
|
{
|
6fa713ca
Karnovsky A
Catalog v 1.2
|
123
124
|
$product = Yii::$app->request->get('product');
|
5aa7418e
Karnovsky A
Base-product#3 fu...
|
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
$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]);
}
return $this->render('product', [
'product' => $product,
'properties' => $groups,
]);
|
85261b14
Karnovsky A
not fixed commite
|
141
142
143
144
145
146
147
148
149
150
151
152
153
|
}
public function actionBrands()
{
return 'actionBrands';
}
public function actionBrand($alias)
{
return 'actionBrand:'. $alias;
}
}
|