Commit aa5c63f430d5fb5703d267fd1fbd9a77bc2f3bf7
1 parent
0dfd8fe2
Filter fixing
Showing
11 changed files
with
616 additions
and
391 deletions
Show diff stats
common/modules/product/helpers/ProductHelper.php
1 | <?php | 1 | <?php |
2 | - | ||
3 | -namespace common\modules\product\helpers; | ||
4 | - | ||
5 | -use common\modules\product\models\Brand; | ||
6 | -use common\modules\product\models\Category; | ||
7 | -use common\modules\product\models\Product; | ||
8 | -use common\modules\product\models\ProductVariant; | ||
9 | -use common\modules\product\models\BrandName; | ||
10 | -use common\modules\product\models\CategoryName; | ||
11 | -use yii\base\Object; | ||
12 | -use Yii; | ||
13 | - | ||
14 | -class ProductHelper extends Object { | ||
15 | - const PRODUCT_TAX_GROUP_ID_TARGET = 20; | ||
16 | - const PRODUCT_TAX_GROUP_ID_YEAR = 21; | ||
17 | - const PRODUCT_TAX_GROUP_ID_SEX = 22; | ||
18 | - | ||
19 | - const PRODUCT_VARIANT_TYPE_COLOR = 1; | ||
20 | - const PRODUCT_VARIANT_TYPE_SIZE = 2; | ||
21 | - | ||
22 | - public static function getCategories() { | ||
23 | - return Category::find()->getTree(); // with('categoryName')-> | ||
24 | - } | ||
25 | - | ||
26 | - public static function getBrands() { | ||
27 | - return Brand::find(); // ->with('brandName') | ||
28 | - } | ||
29 | - | ||
30 | - /* | ||
31 | - * Return custom filter-option link | ||
32 | - * @var array $filter | ||
33 | - * @var array $options | ||
34 | - * @return array | ||
35 | - */ | ||
36 | - public static function getFilterForOption($filter, $key, $value, $remove = false) { | ||
37 | - $result = $filter; | ||
38 | - if (is_array($value)) { | ||
39 | - foreach($value as $value_key => $value_items) { | ||
40 | - if (!is_array($value_items)) { | ||
41 | - $value_items = [$value_items]; | ||
42 | - } | ||
43 | - foreach($value_items as $value_item) { | ||
44 | - if ($remove && isset($result[$key]) && ($i = array_search($value_item, $result[$key][$value_key])) !== FALSE) { | ||
45 | - unset($result[$key][$value_key][$i]); | ||
46 | - if (empty($result[$key][$value_key])) { | ||
47 | - unset($result[$key][$value_key]); | ||
48 | - } | ||
49 | - } else { | ||
50 | - if (!isset($result[$key][$value_key]) || array_search($value_item, $result[$key][$value_key]) === FALSE) { | ||
51 | - $result[$key][$value_key][] = $value_item; | 2 | + |
3 | + namespace common\modules\product\helpers; | ||
4 | + | ||
5 | + use common\modules\product\models\Brand; | ||
6 | + use common\modules\product\models\Category; | ||
7 | + use common\modules\product\models\Product; | ||
8 | + use common\modules\product\models\ProductVariant; | ||
9 | + use common\modules\product\models\BrandName; | ||
10 | + use common\modules\product\models\CategoryName; | ||
11 | + use yii\base\Object; | ||
12 | + use Yii; | ||
13 | + use yii\db\ActiveQuery; | ||
14 | + | ||
15 | + class ProductHelper extends Object | ||
16 | + { | ||
17 | + | ||
18 | + const PRODUCT_TAX_GROUP_ID_TARGET = 20; | ||
19 | + const PRODUCT_TAX_GROUP_ID_YEAR = 21; | ||
20 | + const PRODUCT_TAX_GROUP_ID_SEX = 22; | ||
21 | + | ||
22 | + const PRODUCT_VARIANT_TYPE_COLOR = 1; | ||
23 | + const PRODUCT_VARIANT_TYPE_SIZE = 2; | ||
24 | + | ||
25 | + public static function getCategories() | ||
26 | + { | ||
27 | + return Category::find() | ||
28 | + ->getTree(); // with('categoryName')-> | ||
29 | + } | ||
30 | + | ||
31 | + public static function getBrands() | ||
32 | + { | ||
33 | + return Brand::find(); // ->with('brandName') | ||
34 | + } | ||
35 | + | ||
36 | + /* | ||
37 | + * Return custom filter-option link | ||
38 | + * @var array $filter | ||
39 | + * @var array $options | ||
40 | + * @return array | ||
41 | + */ | ||
42 | + public static function getFilterForOption($filter, $key, $value, $remove = false) | ||
43 | + { | ||
44 | + $result = $filter; | ||
45 | + if(is_array($value)) { | ||
46 | + foreach($value as $value_key => $value_items) { | ||
47 | + if(!is_array($value_items)) { | ||
48 | + $value_items = [ $value_items ]; | ||
49 | + } | ||
50 | + foreach($value_items as $value_item) { | ||
51 | + if($remove && isset( $result[ $key ] ) && ( $i = array_search($value_item, $result[ $key ][ $value_key ]) ) !== false) { | ||
52 | + unset( $result[ $key ][ $value_key ][ $i ] ); | ||
53 | + if(empty( $result[ $key ][ $value_key ] )) { | ||
54 | + unset( $result[ $key ][ $value_key ] ); | ||
55 | + } | ||
56 | + } else { | ||
57 | + if(!isset( $result[ $key ][ $value_key ] ) || array_search($value_item, $result[ $key ][ $value_key ]) === false) { | ||
58 | + $result[ $key ][ $value_key ][] = $value_item; | ||
59 | + } | ||
52 | } | 60 | } |
53 | } | 61 | } |
54 | } | 62 | } |
55 | - } | ||
56 | - } else { | ||
57 | - if ($remove && isset($result[$key]) && ($i = array_search($value, $result[$key])) !== FALSE) { | ||
58 | - unset($result[$key][$i]); | ||
59 | - if (empty($result[$key])) { | ||
60 | - unset($result[$key]); | ||
61 | - } | ||
62 | } else { | 63 | } else { |
63 | - if (!isset($result[$key]) || array_search($value, $result[$key]) === FALSE) { | ||
64 | - $result[$key][] = $value; | 64 | + if($remove && isset( $result[ $key ] ) && ( $i = array_search($value, $result[ $key ]) ) !== false) { |
65 | + unset( $result[ $key ][ $i ] ); | ||
66 | + if(empty( $result[ $key ] )) { | ||
67 | + unset( $result[ $key ] ); | ||
68 | + } | ||
69 | + } else { | ||
70 | + if(!isset( $result[ $key ] ) || array_search($value, $result[ $key ]) === false) { | ||
71 | + $result[ $key ][] = $value; | ||
72 | + } | ||
65 | } | 73 | } |
66 | } | 74 | } |
75 | + return $result; | ||
67 | } | 76 | } |
68 | - return $result; | ||
69 | - } | ||
70 | - | ||
71 | - public static function addLastProsucts($product_id) { | ||
72 | - $last_products = self::getLastProducts(); | ||
73 | - if (!in_array($product_id, $last_products)) { | ||
74 | - $last_products[] = intval($product_id); | ||
75 | - if (count($last_products) > 16) { | ||
76 | - array_shift($last_products); | 77 | + |
78 | + public static function addLastProsucts($product_id) | ||
79 | + { | ||
80 | + $last_products = self::getLastProducts(); | ||
81 | + if(!in_array($product_id, $last_products)) { | ||
82 | + $last_products[] = intval($product_id); | ||
83 | + if(count($last_products) > 16) { | ||
84 | + array_shift($last_products); | ||
85 | + } | ||
86 | + Yii::$app->session->set('last_products', $last_products); | ||
77 | } | 87 | } |
78 | - Yii::$app->session->set('last_products', $last_products); | ||
79 | - } | ||
80 | - } | ||
81 | - | ||
82 | - public static function getLastProducts($as_object = false) { | ||
83 | - $last_products = Yii::$app->session->get('last_products', []); | ||
84 | - if ($as_object) { | ||
85 | - $last_products = Product::find()->joinWith(['variant'])->where([Product::tableName() .'.product_id' => $last_products])->andWhere(['!=', ProductVariant::tableName() .'.stock', 0])->all(); | ||
86 | } | 88 | } |
87 | - return array_reverse($last_products); | ||
88 | - } | ||
89 | - | ||
90 | - public static function getSpecialProducts($type, $count, $sort = null) { | ||
91 | - switch($type) { | ||
92 | - case 'top': | ||
93 | - $data = ['is_top' => true]; | ||
94 | - break; | ||
95 | - case 'new': | ||
96 | - $data = ['is_new' => true]; | ||
97 | - break; | ||
98 | - case 'promo': | ||
99 | - $data = ['akciya' => true]; | ||
100 | - break; | ||
101 | - } | ||
102 | - return Product::find()->joinWith('variants')->where($data)->andWhere(['!=', ProductVariant::tableName() .'.stock', 0])->limit($count)/*->orderBy($sort)*/->all(); | ||
103 | - } | ||
104 | - | ||
105 | - public static function getSimilarProducts($product, $count = 10) { | ||
106 | - if (!is_object($product)) { | ||
107 | - $product = Product::find()->where(['product_id'=>$product])->with('enabledVariants')->one(); | ||
108 | - } | ||
109 | - | ||
110 | - if (!$product->properties) { | ||
111 | - return []; | 89 | + |
90 | + public static function getLastProducts($as_object = false) | ||
91 | + { | ||
92 | + $last_products = Yii::$app->session->get('last_products', [ ]); | ||
93 | + if($as_object) { | ||
94 | + $last_products = Product::find() | ||
95 | + ->joinWith([ 'variant' ]) | ||
96 | + ->where([ Product::tableName() . '.product_id' => $last_products ]) | ||
97 | + ->andWhere([ | ||
98 | + '!=', | ||
99 | + ProductVariant::tableName() . '.stock', | ||
100 | + 0, | ||
101 | + ]) | ||
102 | + ->all(); | ||
103 | + } | ||
104 | + return array_reverse($last_products); | ||
112 | } | 105 | } |
113 | - $product_categories = []; | ||
114 | - foreach ($product->categories as $category) { | ||
115 | - $product_categories[] = $category->category_id; | 106 | + |
107 | + public static function getSpecialProducts($type, $count, $sort = NULL) | ||
108 | + { | ||
109 | + switch($type) { | ||
110 | + case 'top': | ||
111 | + $data = [ 'is_top' => true ]; | ||
112 | + break; | ||
113 | + case 'new': | ||
114 | + $data = [ 'is_new' => true ]; | ||
115 | + break; | ||
116 | + case 'promo': | ||
117 | + $data = [ 'akciya' => true ]; | ||
118 | + break; | ||
119 | + } | ||
120 | + return Product::find() | ||
121 | + ->joinWith('variants') | ||
122 | + ->where($data) | ||
123 | + ->andWhere([ | ||
124 | + '!=', | ||
125 | + ProductVariant::tableName() . '.stock', | ||
126 | + 0, | ||
127 | + ]) | ||
128 | + ->limit($count)/*->orderBy($sort)*/ | ||
129 | + ->all(); | ||
116 | } | 130 | } |
117 | - $query = Product::find() | ||
118 | - ->select('product.product_id') | ||
119 | - ->innerJoinWith('variant') | ||
120 | - ->joinWith('category') | ||
121 | - ->where(['!=', 'product_variant.stock', 0]) | ||
122 | - ->andWhere(['product_category.category_id' => $product_categories]); | ||
123 | -// $query->andWhere(['>=', 'product_variant.price', $product->enabledVariant->price * 0.7]); | ||
124 | -// $query->andWhere(['<=', 'product_variant.price', $product->enabledVariant->price * 1.3]); | ||
125 | - foreach($product->properties as $group) { | ||
126 | - $where = []; | ||
127 | - foreach ($group->_options as $option) { | ||
128 | - $where[] = $option->tax_option_id; | 131 | + |
132 | + public static function getSimilarProducts($product, $count = 10) | ||
133 | + { | ||
134 | + if(!is_object($product)) { | ||
135 | + $product = Product::find() | ||
136 | + ->where([ 'product_id' => $product ]) | ||
137 | + ->with('enabledVariants') | ||
138 | + ->one(); | ||
129 | } | 139 | } |
130 | - if (!$where) { | ||
131 | - continue; | 140 | + |
141 | + if(!$product->properties) { | ||
142 | + return [ ]; | ||
132 | } | 143 | } |
133 | - $query->innerJoin('product_option to'. $group->tax_group_id, 'to'. $group->tax_group_id .'.product_id = product.product_id'); | ||
134 | - $query->andWhere(['to'. $group->tax_group_id .'.option_id' => $where]); | ||
135 | - } | ||
136 | - $query->andWhere(['!=', 'product.product_id', $product->product_id]); | ||
137 | - $query->groupBy('product.product_id'); | ||
138 | - $query->limit($count); | ||
139 | - $products = $query->asArray()->all(); | ||
140 | - foreach ($products as &$_product) { | ||
141 | - $_product = Product::findOne($_product['product_id']); | ||
142 | - } | ||
143 | - return $products; | ||
144 | - } | ||
145 | - | ||
146 | - | ||
147 | - | ||
148 | - public static function _setQueryParams(&$query, $params, $setPriceLimits = true) { | ||
149 | - if (!empty($params['keywords'])) { | ||
150 | - if (!is_array($params['keywords'])) { | ||
151 | - $params['keywords'] = [$params['keywords']]; | 144 | + $product_categories = [ ]; |
145 | + foreach($product->categories as $category) { | ||
146 | + $product_categories[] = $category->category_id; | ||
152 | } | 147 | } |
153 | - foreach ($params['keywords'] as $keyword) { | ||
154 | - $query->orFilterWhere(['ilike', Product::tableName() .'.name', $keyword]); | ||
155 | - $query->orFilterWhere(['ilike', BrandName::tableName() .'.value', $keyword]); | ||
156 | - $query->orFilterWhere(['ilike', CategoryName::tableName() .'.value', $keyword]); | ||
157 | - $query->orFilterWhere(['ilike', ProductVariant::tableName() .'.sku', $keyword]); | 148 | + $query = Product::find() |
149 | + ->select('product.product_id') | ||
150 | + ->innerJoinWith('variant') | ||
151 | + ->joinWith('category') | ||
152 | + ->where([ | ||
153 | + '!=', | ||
154 | + 'product_variant.stock', | ||
155 | + 0, | ||
156 | + ]) | ||
157 | + ->andWhere([ 'product_category.category_id' => $product_categories ]); | ||
158 | + // $query->andWhere(['>=', 'product_variant.price', $product->enabledVariant->price * 0.7]); | ||
159 | + // $query->andWhere(['<=', 'product_variant.price', $product->enabledVariant->price * 1.3]); | ||
160 | + foreach($product->properties as $group) { | ||
161 | + $where = [ ]; | ||
162 | + foreach($group->_options as $option) { | ||
163 | + $where[] = $option->tax_option_id; | ||
164 | + } | ||
165 | + if(!$where) { | ||
166 | + continue; | ||
167 | + } | ||
168 | + $query->innerJoin('product_option to' . $group->tax_group_id, 'to' . $group->tax_group_id . '.product_id = product.product_id'); | ||
169 | + $query->andWhere([ 'to' . $group->tax_group_id . '.option_id' => $where ]); | ||
158 | } | 170 | } |
159 | - } | ||
160 | - | ||
161 | - foreach($params as $key => $param){ | ||
162 | - | ||
163 | - switch ($key) { | ||
164 | - case 'special': | ||
165 | - foreach($param as $key => $value) { | ||
166 | - $query->orFilterWhere([Product::tableName() .'.'. $key => $value]); | ||
167 | - } | ||
168 | - break; | ||
169 | - case 'brands': | ||
170 | - $query->andFilterWhere([Product::tableName() .'.brand_id' => $param]); | ||
171 | - break; | ||
172 | - case 'keywords': | ||
173 | - break; | ||
174 | - case 'prices': | ||
175 | - if ($param['min'] > 0) { | ||
176 | - $query->andWhere(['>=', ProductVariant::tableName() .'.price', $param['min']]); | ||
177 | - } | ||
178 | - if ($param['max'] > 0) { | ||
179 | - $query->andWhere(['<=', ProductVariant::tableName() .'.price', $param['max']]); | ||
180 | - } | ||
181 | - break; | ||
182 | - default: | ||
183 | - $query->andWhere( | ||
184 | - Product::tableName() . '.product_id IN (SELECT product_id AS products FROM product_option INNER JOIN tax_option ON tax_option.tax_option_id = product_option.option_id INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\'))' | ||
185 | - ); | 171 | + $query->andWhere([ |
172 | + '!=', | ||
173 | + 'product.product_id', | ||
174 | + $product->product_id, | ||
175 | + ]); | ||
176 | + $query->groupBy('product.product_id'); | ||
177 | + $query->limit($count); | ||
178 | + $products = $query->asArray() | ||
179 | + ->all(); | ||
180 | + foreach($products as &$_product) { | ||
181 | + $_product = Product::findOne($_product[ 'product_id' ]); | ||
186 | } | 182 | } |
187 | - | 183 | + return $products; |
188 | } | 184 | } |
189 | - | ||
190 | - } | ||
191 | - | ||
192 | - public static function productCountQuery($category = null, $params, $excludeKeys = []) { | ||
193 | - $p = []; | ||
194 | - foreach ($params as $key => $param) { | ||
195 | - if (in_array($key, $excludeKeys)) { | ||
196 | - $p[$key] = $param; | 185 | + |
186 | + /** | ||
187 | + * @param ActiveQuery $query | ||
188 | + * @param $params | ||
189 | + * @param bool $setPriceLimits | ||
190 | + */ | ||
191 | + public static function _setQueryParams(&$query, $params, $setPriceLimits = true) | ||
192 | + { | ||
193 | + if(!empty( $params[ 'keywords' ] )) { | ||
194 | + if(!is_array($params[ 'keywords' ])) { | ||
195 | + $params[ 'keywords' ] = [ $params[ 'keywords' ] ]; | ||
196 | + } | ||
197 | + foreach($params[ 'keywords' ] as $keyword) { | ||
198 | + $query->orFilterWhere([ | ||
199 | + 'ilike', | ||
200 | + Product::tableName() . '.name', | ||
201 | + $keyword, | ||
202 | + ]); | ||
203 | + $query->orFilterWhere([ | ||
204 | + 'ilike', | ||
205 | + BrandName::tableName() . '.value', | ||
206 | + $keyword, | ||
207 | + ]); | ||
208 | + $query->orFilterWhere([ | ||
209 | + 'ilike', | ||
210 | + CategoryName::tableName() . '.value', | ||
211 | + $keyword, | ||
212 | + ]); | ||
213 | + $query->orFilterWhere([ | ||
214 | + 'ilike', | ||
215 | + ProductVariant::tableName() . '.sku', | ||
216 | + $keyword, | ||
217 | + ]); | ||
218 | + } | ||
219 | + } | ||
220 | + | ||
221 | + foreach($params as $key => $param) { | ||
222 | + | ||
223 | + switch($key) { | ||
224 | + case 'special': | ||
225 | + foreach($param as $key => $value) { | ||
226 | + $query->orFilterWhere([ Product::tableName() . '.' . $key => $value ]); | ||
227 | + } | ||
228 | + break; | ||
229 | + case 'brands': | ||
230 | + $query->andFilterWhere([ Product::tableName() . '.brand_id' => $param ]); | ||
231 | + break; | ||
232 | + case 'keywords': | ||
233 | + break; | ||
234 | + case 'prices': | ||
235 | + if($param[ 'min' ] > 0) { | ||
236 | + $query->andWhere([ | ||
237 | + '>=', | ||
238 | + ProductVariant::tableName() . '.price', | ||
239 | + $param[ 'min' ], | ||
240 | + ]); | ||
241 | + } | ||
242 | + if($param[ 'max' ] > 0) { | ||
243 | + $query->andWhere([ | ||
244 | + '<=', | ||
245 | + ProductVariant::tableName() . '.price', | ||
246 | + $param[ 'max' ], | ||
247 | + ]); | ||
248 | + } | ||
249 | + break; | ||
250 | + default: | ||
251 | + $query->andWhere( | ||
252 | + Product::tableName() . '.product_id IN ( | ||
253 | + SELECT DISTINCT products | ||
254 | + FROM ( | ||
255 | + SELECT product_id AS products | ||
256 | + FROM product_option | ||
257 | + INNER JOIN tax_option ON tax_option.tax_option_id = product_option.option_id | ||
258 | + INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id | ||
259 | + WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\') OR product_id IN ( | ||
260 | + (SELECT product_id AS products | ||
261 | + FROM product_variant_option | ||
262 | + INNER JOIN product_variant ON product_variant_option.product_variant_id = product_variant.product_variant_id | ||
263 | + INNER JOIN tax_option ON tax_option.tax_option_id = product_variant_option.option_id | ||
264 | + INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id | ||
265 | + WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\')) | ||
266 | + ) | ||
267 | + ) AS table_name | ||
268 | + )' | ||
269 | + ); | ||
270 | + } | ||
271 | + | ||
197 | } | 272 | } |
273 | + | ||
198 | } | 274 | } |
199 | - /** @var ActiveQuery $query */ | ||
200 | - if (!empty($category)) { | ||
201 | - $query = $category->getProducts(); | ||
202 | - } else { | ||
203 | - $query = Product::find(); | 275 | + |
276 | + public static function productCountQuery($category = NULL, $params, $excludeKeys = [ ]) | ||
277 | + { | ||
278 | + $p = [ ]; | ||
279 | + foreach($params as $key => $param) { | ||
280 | + if(in_array($key, $excludeKeys)) { | ||
281 | + $p[ $key ] = $param; | ||
282 | + } | ||
283 | + } | ||
284 | + /** @var ActiveQuery $query */ | ||
285 | + if(!empty( $category )) { | ||
286 | + $query = $category->getProducts(); | ||
287 | + } else { | ||
288 | + $query = Product::find(); | ||
289 | + } | ||
290 | + ProductHelper::_setQueryParams($query, $params); | ||
291 | + $query->select([ 'COUNT(product.product_id)' ]); | ||
292 | + | ||
293 | + return $query; | ||
204 | } | 294 | } |
205 | - ProductHelper::_setQueryParams($query, $params); | ||
206 | - $query->select(['COUNT(product.product_id)']); | ||
207 | - | ||
208 | - return $query; | ||
209 | - } | ||
210 | -} | ||
211 | \ No newline at end of file | 295 | \ No newline at end of file |
296 | + } | ||
212 | \ No newline at end of file | 297 | \ No newline at end of file |
common/modules/product/models/Category.php
@@ -10,6 +10,7 @@ use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; | @@ -10,6 +10,7 @@ use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; | ||
10 | use common\modules\rubrication\models\TaxGroup; | 10 | use common\modules\rubrication\models\TaxGroup; |
11 | use Yii; | 11 | use Yii; |
12 | use yii\base\ErrorException; | 12 | use yii\base\ErrorException; |
13 | +use yii\db\Query; | ||
13 | 14 | ||
14 | /** | 15 | /** |
15 | * This is the model class for table "category". | 16 | * This is the model class for table "category". |
@@ -225,5 +226,57 @@ class Category extends \yii\db\ActiveRecord | @@ -225,5 +226,57 @@ class Category extends \yii\db\ActiveRecord | ||
225 | CategoryName::deleteAll(['category_id' => $this->category_id]); | 226 | CategoryName::deleteAll(['category_id' => $this->category_id]); |
226 | return true; | 227 | return true; |
227 | } | 228 | } |
229 | + | ||
230 | + public function getActiveFilters() { | ||
231 | + $query1 = (new Query()) | ||
232 | + ->distinct() | ||
233 | + ->select([ | ||
234 | + 'option_id', | ||
235 | + 'tax_option.*', | ||
236 | + 'tax_group.*', | ||
237 | + 'tax_option.alias as option_alias', | ||
238 | + 'tax_group.alias as group_alias', | ||
239 | + 'tax_value_string.value as value', | ||
240 | + 'tax_option.sort AS tax_option_sort', | ||
241 | + 'tax_group.sort AS tax_group_sort', | ||
242 | + ]) | ||
243 | + ->from('tax_option') | ||
244 | + ->innerJoin('product_variant_option', 'tax_option.tax_option_id = product_variant_option.option_id') | ||
245 | + ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id') | ||
246 | + ->innerJoin('product_variant', 'product_variant.product_variant_id = product_variant_option.product_variant_id') | ||
247 | + ->innerJoin('product', 'product.product_id = product_variant.product_id') | ||
248 | + ->innerJoin('product_category', 'product_category.product_id = product.product_id') | ||
249 | + ->innerJoin('tax_value_string', 'tax_value_string.tax_option_id = tax_option.tax_option_id') | ||
250 | + ->where(['product_category.category_id' => $this->category_id]) | ||
251 | + ->andWhere(['!=', 'product_variant.stock', 0]); | ||
252 | + | ||
253 | + $query2 = (new Query()) | ||
254 | + ->distinct() | ||
255 | + ->select([ | ||
256 | + 'option_id', | ||
257 | + 'tax_option.*', | ||
258 | + 'tax_group.*', | ||
259 | + 'tax_option.alias as option_alias', | ||
260 | + 'tax_group.alias as group_alias', | ||
261 | + 'tax_value_string.value as value', | ||
262 | + 'tax_option.sort AS tax_option_sort', | ||
263 | + 'tax_group.sort AS tax_group_sort', | ||
264 | + ]) | ||
265 | + ->from('tax_option') | ||
266 | + ->innerJoin('product_option', 'tax_option.tax_option_id = product_option.option_id') | ||
267 | + ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id') | ||
268 | + ->innerJoin('product', 'product.product_id = product_option.product_id') | ||
269 | + ->innerJoin('product_category', 'product_category.product_id = product.product_id') | ||
270 | + ->innerJoin('product_variant', 'product_variant.product_id = product.product_id') | ||
271 | + ->innerJoin('tax_value_string', 'tax_value_string.tax_option_id = tax_option.tax_option_id') | ||
272 | + ->where(['product_category.category_id' => $this->category_id]) | ||
273 | + ->andWhere(['!=', 'product_variant.stock', 0]) | ||
274 | + ->orderBy('tax_group_sort, tax_option_sort'); | ||
275 | + $query3 = (new Query()) | ||
276 | + ->select('*') | ||
277 | + ->from(['subquery' => $query1->union($query2)]) | ||
278 | + ->orderBy('tax_group_sort, tax_option_sort'); | ||
279 | + return $query3; | ||
280 | + } | ||
228 | 281 | ||
229 | } | 282 | } |
common/modules/product/models/Product.php
@@ -262,6 +262,20 @@ class Product extends \yii\db\ActiveRecord | @@ -262,6 +262,20 @@ class Product extends \yii\db\ActiveRecord | ||
262 | } | 262 | } |
263 | return $groups; | 263 | return $groups; |
264 | } | 264 | } |
265 | + | ||
266 | + public function getActiveProperties() { | ||
267 | + $groups = $options = []; | ||
268 | + foreach ($this->options as $option) { | ||
269 | + $options[$option->tax_group_id][] = $option; | ||
270 | + } | ||
271 | + foreach (TaxGroup::find()->where(['tax_group_id' => array_keys($options), 'display' => TRUE])->all() as $group) { | ||
272 | + if (!empty($options[$group->tax_group_id])) { | ||
273 | + $group->_options = $options[$group->tax_group_id]; | ||
274 | + $groups[] = $group; | ||
275 | + } | ||
276 | + } | ||
277 | + return $groups; | ||
278 | + } | ||
265 | 279 | ||
266 | public function getStocks() { | 280 | public function getStocks() { |
267 | return $this->hasMany(Stock::className(), ['stock_id' => 'stock_id'])->viaTable(ProductStock::tableName(), ['product_id' => 'product_id']); | 281 | return $this->hasMany(Stock::className(), ['stock_id' => 'stock_id'])->viaTable(ProductStock::tableName(), ['product_id' => 'product_id']); |
common/modules/rubrication/models/TaxGroup.php
@@ -17,6 +17,8 @@ use Yii; | @@ -17,6 +17,8 @@ use Yii; | ||
17 | * @property string $settings | 17 | * @property string $settings |
18 | * @property boolean $is_filter | 18 | * @property boolean $is_filter |
19 | * @property integer $level | 19 | * @property integer $level |
20 | + * @property integer $sort | ||
21 | + * @property boolean $display | ||
20 | * @property TaxGroupToGroup[] $taxGroupToGroups | 22 | * @property TaxGroupToGroup[] $taxGroupToGroups |
21 | * @property TaxGroupToGroup[] $taxGroupToGroups0 | 23 | * @property TaxGroupToGroup[] $taxGroupToGroups0 |
22 | * @property TaxOption[] $taxOptions | 24 | * @property TaxOption[] $taxOptions |
@@ -62,8 +64,8 @@ class TaxGroup extends \yii\db\ActiveRecord | @@ -62,8 +64,8 @@ class TaxGroup extends \yii\db\ActiveRecord | ||
62 | return [ | 64 | return [ |
63 | [['name', 'module'], 'required'], | 65 | [['name', 'module'], 'required'], |
64 | [['description', 'settings'], 'string'], | 66 | [['description', 'settings'], 'string'], |
65 | - [['hierarchical', 'is_filter'], 'boolean'], | ||
66 | - [['level'], 'integer'], | 67 | + [['hierarchical', 'is_filter', 'display'], 'boolean'], |
68 | + [['level', 'sort'], 'integer'], | ||
67 | [['alias', 'module'], 'string', 'max' => 50], | 69 | [['alias', 'module'], 'string', 'max' => 50], |
68 | [['name'], 'string', 'max' => 255], | 70 | [['name'], 'string', 'max' => 255], |
69 | [['group_to_category'], 'safe'] | 71 | [['group_to_category'], 'safe'] |
@@ -84,6 +86,8 @@ class TaxGroup extends \yii\db\ActiveRecord | @@ -84,6 +86,8 @@ class TaxGroup extends \yii\db\ActiveRecord | ||
84 | 'hierarchical' => 'Hierarchical', | 86 | 'hierarchical' => 'Hierarchical', |
85 | // 'settings' => 'Settings', | 87 | // 'settings' => 'Settings', |
86 | 'is_filter' => 'Use in filter', | 88 | 'is_filter' => 'Use in filter', |
89 | + 'sort' => 'Sort', | ||
90 | + 'display' => 'Display', | ||
87 | ]; | 91 | ]; |
88 | } | 92 | } |
89 | 93 |
common/modules/rubrication/views/tax-group/_form.php
@@ -35,6 +35,10 @@ use common\components\artboxtree\ArtboxTreeHelper; | @@ -35,6 +35,10 @@ use common\components\artboxtree\ArtboxTreeHelper; | ||
35 | <?php /*= $form->field($model, 'hierarchical')->checkbox()*/ ?> | 35 | <?php /*= $form->field($model, 'hierarchical')->checkbox()*/ ?> |
36 | 36 | ||
37 | <?= $form->field($model, 'is_filter')->checkbox() ?> | 37 | <?= $form->field($model, 'is_filter')->checkbox() ?> |
38 | + | ||
39 | + <?= $form->field($model, 'display')->checkbox() ?> | ||
40 | + | ||
41 | + <?= $form->field($model, 'sort')->textInput() ?> | ||
38 | 42 | ||
39 | <div class="form-group"> | 43 | <div class="form-group"> |
40 | <?= Html::submitButton($model->isNewRecord ? Yii::t('rubrication', 'Create') : Yii::t('rubrication', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | 44 | <?= Html::submitButton($model->isNewRecord ? Yii::t('rubrication', 'Create') : Yii::t('rubrication', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
console/migrations/m160810_074009_add_tax_option_sort.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m160810_074009_add_tax_option_sort extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + $this->addColumn('tax_group', 'sort', $this->integer()->defaultValue(0)); | ||
10 | + } | ||
11 | + | ||
12 | + public function down() | ||
13 | + { | ||
14 | + $this->dropColumn('tax_group', 'sort'); | ||
15 | + } | ||
16 | +} |
console/migrations/m160810_081231_add_tax_option_display.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +class m160810_081231_add_tax_option_display extends Migration | ||
6 | +{ | ||
7 | + public function up() | ||
8 | + { | ||
9 | + $this->addColumn('tax_group', 'display', $this->boolean()->defaultValue(TRUE)); | ||
10 | + } | ||
11 | + | ||
12 | + public function down() | ||
13 | + { | ||
14 | + $this->dropColumn('tax_group', 'display'); | ||
15 | + } | ||
16 | +} |
frontend/controllers/CatalogController.php
1 | <?php | 1 | <?php |
2 | - | ||
3 | -namespace frontend\controllers; | ||
4 | - | ||
5 | -use common\modules\product\Filter; | ||
6 | -use common\modules\product\helpers\ProductHelper; | ||
7 | -use common\modules\rubrication\models\TaxOptionSearch; | ||
8 | -use frontend\models\ProductFrontendSearch; | ||
9 | -use Yii; | ||
10 | -use common\modules\product\models\Brand; | ||
11 | -use common\modules\product\models\BrandSearch; | ||
12 | -use common\modules\product\models\Category; | ||
13 | -use common\modules\product\models\CategorySearch; | ||
14 | -use common\modules\product\models\Product; | ||
15 | -use common\modules\product\models\ProductCategory; | ||
16 | -use common\modules\product\models\ProductOption; | ||
17 | -use common\modules\product\models\ProductSearch; | ||
18 | -use common\modules\product\models\ProductVariant; | ||
19 | -use common\modules\rubrication\models\TaxGroup; | ||
20 | -use common\modules\rubrication\models\TaxOption; | ||
21 | -use common\modules\rubrication\models\TaxValueString; | ||
22 | -use yii\data\ActiveDataProvider; | ||
23 | -use yii\data\Pagination; | ||
24 | -use yii\data\Sort; | ||
25 | -use yii\db\ActiveQuery; | ||
26 | -use yii\helpers\ArrayHelper; | ||
27 | -use yii\web\HttpException; | ||
28 | - | ||
29 | -class CatalogController extends \yii\web\Controller | ||
30 | -{ | ||
31 | - public function actionSearch() { | ||
32 | - // @todo | ||
33 | - } | ||
34 | - | ||
35 | - public function actionCategory() | 2 | + |
3 | + namespace frontend\controllers; | ||
4 | + | ||
5 | + use common\modules\product\Filter; | ||
6 | + use common\modules\product\helpers\ProductHelper; | ||
7 | + use common\modules\rubrication\models\TaxOptionSearch; | ||
8 | + use frontend\models\ProductFrontendSearch; | ||
9 | + use Yii; | ||
10 | + use common\modules\product\models\Brand; | ||
11 | + use common\modules\product\models\BrandSearch; | ||
12 | + use common\modules\product\models\Category; | ||
13 | + use common\modules\product\models\CategorySearch; | ||
14 | + use common\modules\product\models\Product; | ||
15 | + use common\modules\product\models\ProductCategory; | ||
16 | + use common\modules\product\models\ProductOption; | ||
17 | + use common\modules\product\models\ProductSearch; | ||
18 | + use common\modules\product\models\ProductVariant; | ||
19 | + use common\modules\rubrication\models\TaxGroup; | ||
20 | + use common\modules\rubrication\models\TaxOption; | ||
21 | + use common\modules\rubrication\models\TaxValueString; | ||
22 | + use yii\data\ActiveDataProvider; | ||
23 | + use yii\data\Pagination; | ||
24 | + use yii\data\Sort; | ||
25 | + use yii\db\ActiveQuery; | ||
26 | + use yii\helpers\ArrayHelper; | ||
27 | + use yii\web\HttpException; | ||
28 | + | ||
29 | + class CatalogController extends \yii\web\Controller | ||
36 | { | 30 | { |
37 | - /** @var Category $category */ | ||
38 | - $category = Yii::$app->request->get('category'); | ||
39 | - $filter = Yii::$app->request->get('filters', []); | ||
40 | - $filter_check = $filter; | ||
41 | - | ||
42 | - if (empty($category->category_id) && empty($word)) { | ||
43 | - return $this->render( | ||
44 | - 'catalog' | ||
45 | - ); | 31 | + |
32 | + public function actionSearch() | ||
33 | + { | ||
34 | + // @todo | ||
46 | } | 35 | } |
47 | - | ||
48 | - | ||
49 | - $params = []; | ||
50 | - | ||
51 | - $optionsList = ArrayHelper::getColumn(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(),'alias'); | ||
52 | - | ||
53 | - if ( !empty($filter['brands']) ) { | ||
54 | - unset($filter_check['brands']); | ||
55 | - $brands = Brand::find()->select('brand_id')->where(['in', 'alias', $filter['brands']])->all(); | ||
56 | - $params['brands'] = []; | ||
57 | - foreach ($brands as $brand) { | ||
58 | - $params['brands'][] = $brand->brand_id; | 36 | + |
37 | + public function actionCategory() | ||
38 | + { | ||
39 | + /** @var Category $category */ | ||
40 | + $category = Yii::$app->request->get('category'); | ||
41 | + $filter = Yii::$app->request->get('filters', [ ]); | ||
42 | + $filter_check = $filter; | ||
43 | + | ||
44 | + if(empty( $category->category_id ) && empty( $word )) { | ||
45 | + return $this->render('catalog'); | ||
59 | } | 46 | } |
60 | - } | ||
61 | - | ||
62 | - if ( !empty($filter['special']) ) { | ||
63 | - unset($filter_check['special']); | ||
64 | - if (!is_array($filter['special'])) { | ||
65 | - $filter['special'] = [$filter['special']]; | 47 | + |
48 | + $params = [ ]; | ||
49 | + | ||
50 | + $optionsList = ArrayHelper::getColumn(TaxGroup::find() | ||
51 | + ->where([ 'is_filter' => 'TRUE' ]) | ||
52 | + ->all(), 'alias'); | ||
53 | + | ||
54 | + if(!empty( $filter[ 'brands' ] )) { | ||
55 | + unset( $filter_check[ 'brands' ] ); | ||
56 | + $brands = Brand::find() | ||
57 | + ->select('brand_id') | ||
58 | + ->where([ | ||
59 | + 'in', | ||
60 | + 'alias', | ||
61 | + $filter[ 'brands' ], | ||
62 | + ]) | ||
63 | + ->all(); | ||
64 | + $params[ 'brands' ] = [ ]; | ||
65 | + foreach($brands as $brand) { | ||
66 | + $params[ 'brands' ][] = $brand->brand_id; | ||
67 | + } | ||
66 | } | 68 | } |
67 | - if (in_array('new', $filter['special'])) { | ||
68 | - $params['special']['is_new'] = true; | 69 | + |
70 | + if(!empty( $filter[ 'special' ] )) { | ||
71 | + unset( $filter_check[ 'special' ] ); | ||
72 | + if(!is_array($filter[ 'special' ])) { | ||
73 | + $filter[ 'special' ] = [ $filter[ 'special' ] ]; | ||
74 | + } | ||
75 | + if(in_array('new', $filter[ 'special' ])) { | ||
76 | + $params[ 'special' ][ 'is_new' ] = true; | ||
77 | + } | ||
78 | + if(in_array('top', $filter[ 'special' ])) { | ||
79 | + $params[ 'special' ][ 'is_top' ] = true; | ||
80 | + } | ||
81 | + if(in_array('promo', $filter[ 'special' ])) { | ||
82 | + $params[ 'special' ][ 'akciya' ] = true; | ||
83 | + } | ||
69 | } | 84 | } |
70 | - if (in_array('top', $filter['special'])) { | ||
71 | - $params['special']['is_top'] = true; | 85 | + |
86 | + if(!empty( $filter[ 'prices' ] )) { | ||
87 | + unset( $filter_check[ 'prices' ] ); | ||
88 | + $params[ 'prices' ] = $filter[ 'prices' ]; | ||
72 | } | 89 | } |
73 | - if (in_array('promo', $filter['special'])) { | ||
74 | - $params['special']['akciya'] = true; | 90 | + |
91 | + foreach($optionsList as $optionList) { | ||
92 | + | ||
93 | + if(isset( $filter[ $optionList ] )) { | ||
94 | + unset( $filter_check[ $optionList ] ); | ||
95 | + $params[ $optionList ] = $filter[ $optionList ]; | ||
96 | + } | ||
97 | + | ||
75 | } | 98 | } |
76 | - } | ||
77 | - | ||
78 | - | ||
79 | - if ( !empty($filter['prices']) ) { | ||
80 | - unset($filter_check['prices']); | ||
81 | - $params['prices'] = $filter['prices']; | ||
82 | - } | ||
83 | - | ||
84 | - | ||
85 | - | ||
86 | - foreach($optionsList as $optionList){ | ||
87 | - | ||
88 | - if(isset($filter[$optionList])){ | ||
89 | - unset($filter_check[$optionList]); | ||
90 | - $params[$optionList] = $filter[$optionList]; | 99 | + |
100 | + if(!empty( $filter_check )) { | ||
101 | + $filter = array_diff_key($filter, $filter_check); | ||
102 | + Yii::$app->response->redirect([ | ||
103 | + 'catalog/category', | ||
104 | + 'category' => $category, | ||
105 | + 'filters' => $filter, | ||
106 | + ], 301); | ||
91 | } | 107 | } |
92 | - | ||
93 | - } | ||
94 | - | ||
95 | - if(!empty($filter_check)){ | ||
96 | - $filter = array_diff_key($filter,$filter_check); | ||
97 | - Yii::$app->response->redirect(['catalog/category', 'category' => $category, 'filters' =>$filter],301); | 108 | + |
109 | + $productModel = new ProductFrontendSearch(); | ||
110 | + //$productQuery = $productModel->getSearchQuery($category, $params); | ||
111 | + $productProvider = $productModel->search($category, $params); | ||
112 | + | ||
113 | + $brandModel = new BrandSearch(); | ||
114 | + $brands = $brandModel->getBrands($category, $params) | ||
115 | + ->all(); | ||
116 | + // Old filters | ||
117 | + // $optionsQuery = $productModel->optionsForCategory($category, $params); | ||
118 | + // $groups = []; | ||
119 | + // | ||
120 | + // | ||
121 | + // foreach ($optionsQuery->all() as $option) { | ||
122 | + // if (!isset($groups[$option->tax_group_id])) { | ||
123 | + // $groups[$option->tax_group_id] = $option->taxGroup; | ||
124 | + // $groups[$option->tax_group_id]->_options = []; | ||
125 | + // } | ||
126 | + // $groups[$option->tax_group_id]->_options[] = $option; | ||
127 | + // } | ||
128 | + // foreach($groups as $i => $group) { | ||
129 | + // if (empty($group->_options)) | ||
130 | + // unset($groups[$i]); | ||
131 | + // } | ||
132 | + // New filters | ||
133 | + $groups = $category->getActiveFilters()->all(); | ||
134 | + $groups = ArrayHelper::index($groups, null, 'name'); | ||
135 | + | ||
136 | + $priceLimits = $productModel->priceLimits($category, $params); | ||
137 | + | ||
138 | + /* | ||
139 | + * Greedy search for comments and rating | ||
140 | + */ | ||
141 | + $query = $productProvider->query; | ||
142 | + $query->with([ | ||
143 | + 'comments', | ||
144 | + 'averageRating', | ||
145 | + ]); | ||
146 | + /* | ||
147 | + * End of greedy search for rating and comments | ||
148 | + */ | ||
149 | + | ||
150 | + return $this->render('products', [ | ||
151 | + 'category' => $category, | ||
152 | + 'brandModel' => $brandModel, | ||
153 | + 'brands' => $brands, | ||
154 | + 'filter' => $filter, | ||
155 | + 'params' => $params, | ||
156 | + 'productModel' => $productModel, | ||
157 | + 'productProvider' => $productProvider, | ||
158 | + 'groups' => $groups, | ||
159 | + 'priceLimits' => $priceLimits, | ||
160 | + ]); | ||
161 | + | ||
98 | } | 162 | } |
99 | - | ||
100 | - $productModel = new ProductFrontendSearch(); | ||
101 | - //$productQuery = $productModel->getSearchQuery($category, $params); | ||
102 | - $productProvider = $productModel->search($category, $params); | ||
103 | - | ||
104 | - $brandModel = new BrandSearch(); | ||
105 | - $brands = $brandModel->getBrands($category, $params)->all(); | ||
106 | - | ||
107 | - $optionsQuery = $productModel->optionsForCategory($category, $params); | ||
108 | - $groups = []; | ||
109 | - | ||
110 | - | ||
111 | - foreach ($optionsQuery->all() as $option) { | ||
112 | - if (!isset($groups[$option->tax_group_id])) { | ||
113 | - $groups[$option->tax_group_id] = $option->taxGroup; | ||
114 | - $groups[$option->tax_group_id]->_options = []; | 163 | + |
164 | + public function actionProduct() | ||
165 | + { | ||
166 | + /** @var Product $product */ | ||
167 | + $product = Yii::$app->request->get('product'); | ||
168 | + | ||
169 | + if(!$product->enabledVariant) { | ||
170 | + throw new HttpException(404, 'Товар не найден'); | ||
115 | } | 171 | } |
116 | - $groups[$option->tax_group_id]->_options[] = $option; | 172 | + |
173 | + ProductHelper::addLastProsucts($product->product_id); | ||
174 | + | ||
175 | + return $this->render('product', [ | ||
176 | + 'product' => $product, | ||
177 | + 'category' => $product->category, | ||
178 | + ]); | ||
117 | } | 179 | } |
118 | - foreach($groups as $i => $group) { | ||
119 | - if (empty($group->_options)) | ||
120 | - unset($groups[$i]); | 180 | + |
181 | + public function actionBrands() | ||
182 | + { | ||
183 | + $dataProvider = new ActiveDataProvider([ | ||
184 | + 'query' => Brand::find() | ||
185 | + ->joinWith('brandName') | ||
186 | + ->orderBy('brand_name.value'), | ||
187 | + 'pagination' => [ | ||
188 | + 'pageSize' => -1, | ||
189 | + ], | ||
190 | + ]); | ||
191 | + | ||
192 | + return $this->render('brands', [ | ||
193 | + 'dataProvider' => $dataProvider, | ||
194 | + ]); | ||
121 | } | 195 | } |
122 | - | ||
123 | - $priceLimits = $productModel->priceLimits($category, $params); | ||
124 | - | ||
125 | - /* | ||
126 | - * Greedy search for comments and rating | ||
127 | - */ | ||
128 | - $query = $productProvider->query; | ||
129 | - $query->with(['comments', 'averageRating']); | ||
130 | - /* | ||
131 | - * End of greedy search for rating and comments | ||
132 | - */ | ||
133 | - | ||
134 | - return $this->render( | ||
135 | - 'products', | ||
136 | - [ | ||
137 | - 'category' => $category, | ||
138 | - 'brandModel' => $brandModel, | ||
139 | - 'brands' => $brands, | ||
140 | - 'filter' => $filter, | ||
141 | - 'params' => $params, | ||
142 | - 'productModel' => $productModel, | ||
143 | - 'productProvider' => $productProvider, | ||
144 | - 'groups' => $groups, | ||
145 | - 'priceLimits' => $priceLimits, | ||
146 | - ] | ||
147 | - ); | ||
148 | - | ||
149 | - } | ||
150 | - | ||
151 | - public function actionProduct() | ||
152 | - { | ||
153 | - /** @var Product $product */ | ||
154 | - $product = Yii::$app->request->get('product'); | ||
155 | - | ||
156 | - if(!$product->enabledVariant) { | ||
157 | - throw new HttpException(404, 'Товар не найден'); | 196 | + |
197 | + public function actionBrand($brand) | ||
198 | + { | ||
199 | + $brand = BrandSearch::findByAlias($brand); | ||
200 | + | ||
201 | + $params = [ | ||
202 | + 'brands' => $brand->brand_id, | ||
203 | + ]; | ||
204 | + | ||
205 | + $productModel = new ProductFrontendSearch(); | ||
206 | + $productProvider = $productModel->search(NULL, $params); | ||
207 | + | ||
208 | + $priceLimits = $productModel->priceLimits(NULL, $params); | ||
209 | + | ||
210 | + return $this->render('brand', [ | ||
211 | + 'productModel' => $productModel, | ||
212 | + 'productProvider' => $productProvider, | ||
213 | + 'brand' => $brand, | ||
214 | + 'priceLimits' => $priceLimits, | ||
215 | + ]); | ||
158 | } | 216 | } |
159 | - | ||
160 | - ProductHelper::addLastProsucts($product->product_id); | ||
161 | - | ||
162 | - return $this->render('product', [ | ||
163 | - 'product' => $product, | ||
164 | - 'category' => $product->category, | ||
165 | - ]); | ||
166 | - } | ||
167 | - | ||
168 | - public function actionBrands() | ||
169 | - { | ||
170 | - $dataProvider = new ActiveDataProvider([ | ||
171 | - 'query' => Brand::find()->joinWith('brandName')->orderBy('brand_name.value'), | ||
172 | - 'pagination' => [ | ||
173 | - 'pageSize' => -1, | ||
174 | - ] | ||
175 | - ]); | ||
176 | - | ||
177 | - return $this->render('brands', [ | ||
178 | - 'dataProvider' => $dataProvider, | ||
179 | - ]); | ||
180 | - } | ||
181 | - | ||
182 | - public function actionBrand($brand) | ||
183 | - { | ||
184 | - $brand = BrandSearch::findByAlias($brand); | ||
185 | - | ||
186 | - $params = [ | ||
187 | - 'brands' => $brand->brand_id, | ||
188 | - ]; | ||
189 | - | ||
190 | - $productModel = new ProductFrontendSearch(); | ||
191 | - $productProvider = $productModel->search(null, $params); | ||
192 | - | ||
193 | - $priceLimits = $productModel->priceLimits(null, $params); | ||
194 | - | ||
195 | - return $this->render('brand', [ | ||
196 | - 'productModel' => $productModel, | ||
197 | - 'productProvider' => $productProvider, | ||
198 | - 'brand' => $brand, | ||
199 | - 'priceLimits' => $priceLimits, | ||
200 | - ]); | 217 | + |
201 | } | 218 | } |
202 | - | ||
203 | -} |
frontend/models/ProductFrontendSearch.php
@@ -48,8 +48,7 @@ class ProductFrontendSearch extends Product { | @@ -48,8 +48,7 @@ class ProductFrontendSearch extends Product { | ||
48 | * @return ActiveDataProvider | 48 | * @return ActiveDataProvider |
49 | */ | 49 | */ |
50 | public function search($category = null, $params = []) { | 50 | public function search($category = null, $params = []) { |
51 | - | ||
52 | - | 51 | + |
53 | $dataProvider = new ActiveDataProvider([ | 52 | $dataProvider = new ActiveDataProvider([ |
54 | 'query' => $this->getSearchQuery($category, $params), | 53 | 'query' => $this->getSearchQuery($category, $params), |
55 | 'pagination' => [ | 54 | 'pagination' => [ |
frontend/views/catalog/product.php
@@ -228,7 +228,7 @@ | @@ -228,7 +228,7 @@ | ||
228 | <li><a href="#">Характеристики</a> | 228 | <li><a href="#">Характеристики</a> |
229 | <div class="info"> | 229 | <div class="info"> |
230 | <p>Бренд: <?= $product->brand->name ?></p> | 230 | <p>Бренд: <?= $product->brand->name ?></p> |
231 | - <?php foreach($product->properties as $group): ?> | 231 | + <?php foreach($product->activeProperties as $group): ?> |
232 | <p><?= $group->name ?> <?php foreach($group->_options as $option) : ?> <?= $option->ValueRenderHTML ?><?php endforeach ?></p> | 232 | <p><?= $group->name ?> <?php foreach($group->_options as $option) : ?> <?= $option->ValueRenderHTML ?><?php endforeach ?></p> |
233 | <?php endforeach; ?> | 233 | <?php endforeach; ?> |
234 | </div> | 234 | </div> |
frontend/views/catalog/products.php
@@ -2,9 +2,9 @@ | @@ -2,9 +2,9 @@ | ||
2 | 2 | ||
3 | /** @var $this \yii\web\View */ | 3 | /** @var $this \yii\web\View */ |
4 | /** @var $productProvider \yii\data\ActiveDataProvider */ | 4 | /** @var $productProvider \yii\data\ActiveDataProvider */ |
5 | - | ||
6 | - | ||
7 | -use yii\helpers\Url; | 5 | + |
6 | + use yii\helpers\ArrayHelper; | ||
7 | + use yii\helpers\Url; | ||
8 | use yii\widgets\Breadcrumbs; | 8 | use yii\widgets\Breadcrumbs; |
9 | use yii\web\View; | 9 | use yii\web\View; |
10 | use common\modules\product\helpers\ProductHelper; | 10 | use common\modules\product\helpers\ProductHelper; |
@@ -62,9 +62,7 @@ $this->registerJsFile(Yii::getAlias('@web/js/ion.rangeSlider.js'),[ | @@ -62,9 +62,7 @@ $this->registerJsFile(Yii::getAlias('@web/js/ion.rangeSlider.js'),[ | ||
62 | }); | 62 | }); |
63 | <?php endif?> | 63 | <?php endif?> |
64 | </script> | 64 | </script> |
65 | - | ||
66 | - | ||
67 | - | 65 | + |
68 | <div class="loyout"> | 66 | <div class="loyout"> |
69 | <div class="leftbar"> | 67 | <div class="leftbar"> |
70 | <?php /* | 68 | <?php /* |
@@ -125,23 +123,44 @@ $this->registerJsFile(Yii::getAlias('@web/js/ion.rangeSlider.js'),[ | @@ -125,23 +123,44 @@ $this->registerJsFile(Yii::getAlias('@web/js/ion.rangeSlider.js'),[ | ||
125 | <?php endif?> | 123 | <?php endif?> |
126 | 124 | ||
127 | <?php if (!empty($groups)) :?> | 125 | <?php if (!empty($groups)) :?> |
126 | + <?php | ||
127 | + foreach($groups as $group_name => $group) { | ||
128 | + ?> | ||
129 | + <div class="filters"> | ||
130 | + <div class="begin"><?= $group_name?></div> | ||
131 | + <ul> | ||
132 | + <?php foreach($group as $option) : | ||
133 | + $checked = (isset($filter[$option['group_alias']]) && in_array($option['option_alias'], $filter[$option['group_alias']])); | ||
134 | + $option_url = Url::to(['catalog/category', 'category' => $category, 'filters' => FilterHelper::getFilterForOption($filter, $option['group_alias'], $option['option_alias'], $checked)]); | ||
135 | + ?> | ||
136 | + <li> | ||
137 | + <input type="checkbox" onchange="document.location='<?= $option_url?>'" class="features-option" <?php /* name="option[<?= $group->alias?>][]"value="<?= $option->alias?>"*/?><?= $checked ? ' checked' : ''?> /> | ||
138 | + | ||
139 | + <a href="<?= $option_url?>"><?= $option['value']?></a> | ||
140 | + </li> | ||
141 | + <?php endforeach?> | ||
142 | + </ul> | ||
143 | + </div> | ||
144 | + <?php | ||
145 | + } | ||
146 | + /*?> | ||
128 | <?php foreach($groups as $group) :?> | 147 | <?php foreach($groups as $group) :?> |
129 | <div class="filters"> | 148 | <div class="filters"> |
130 | - <div class="begin"><?= $group->name?></div> | 149 | + <div class="begin"><?= $group['name']?></div> |
131 | <ul> | 150 | <ul> |
132 | <?php foreach($group->_options as $option) : | 151 | <?php foreach($group->_options as $option) : |
133 | $checked = (isset($filter[$group->alias]) && in_array($option->alias, $filter[$group->alias])); | 152 | $checked = (isset($filter[$group->alias]) && in_array($option->alias, $filter[$group->alias])); |
134 | $option_url = Url::to(['catalog/category', 'category' => $category, 'filters' => FilterHelper::getFilterForOption($filter, $option->taxGroup->alias, $option->alias, $checked)]); | 153 | $option_url = Url::to(['catalog/category', 'category' => $category, 'filters' => FilterHelper::getFilterForOption($filter, $option->taxGroup->alias, $option->alias, $checked)]); |
135 | ?> | 154 | ?> |
136 | <li> | 155 | <li> |
137 | - <input type="checkbox" onchange="document.location='<?= $option_url?>'" class="features-option" <?php /* name="option[<?= $group->alias?>][]"value="<?= $option->alias?>"*/?><?= $checked ? ' checked' : ''?> /> | 156 | + <input type="checkbox" onchange="document.location='<?= $option_url?>'" class="features-option" <?php /* name="option[<?= $group->alias?>][]"value="<?= $option->alias?>"*//*?><?= $checked ? ' checked' : ''?> /> |
138 | 157 | ||
139 | <a href="<?= $option_url?>"><?= $option->ValueRenderHTML?></a> | 158 | <a href="<?= $option_url?>"><?= $option->ValueRenderHTML?></a> |
140 | </li> | 159 | </li> |
141 | <?php endforeach?> | 160 | <?php endforeach?> |
142 | </ul> | 161 | </ul> |
143 | </div> | 162 | </div> |
144 | - <?php endforeach?> | 163 | + <?php endforeach */?> |
145 | <?php endif?> | 164 | <?php endif?> |
146 | 165 | ||
147 | <?php if ($priceLimits['min'] < $priceLimits['max']) :?> | 166 | <?php if ($priceLimits['min'] < $priceLimits['max']) :?> |