Commit ee3dba29960aa6187450b4b15e4f60f0b102fd76

Authored by Administrator
1 parent 9ebdab4f

add variantSku

Showing 2 changed files with 366 additions and 354 deletions   Show diff stats
helpers/FilterHelper.php
1 1 <?php
2 2  
3   -namespace artweb\artbox\ecommerce\helpers;
4   -
5   -use artweb\artbox\ecommerce\models\BrandLang;
6   -use artweb\artbox\ecommerce\models\CategoryLang;
7   -use artweb\artbox\ecommerce\models\Product;
8   -use artweb\artbox\ecommerce\models\ProductLang;
9   -use artweb\artbox\ecommerce\models\ProductVariant;
10   -use artweb\artbox\ecommerce\models\ProductVariantLang;
11   -use artweb\artbox\ecommerce\models\TaxGroup;
12   -use yii\base\Object;
13   -use yii\db\ActiveQuery;
14   -use yii\db\Query;
15   -use yii\helpers\ArrayHelper;
16   -
17   -class FilterHelper extends Object
18   -{
19   -
20   - public static $optionsList = [];
21   -
22   - /**
23   - * Get TaxGroups
24   - *
25   - * @return array
26   - */
27   - public static function optionsTemplate()
  3 + namespace artweb\artbox\ecommerce\helpers;
  4 +
  5 + use artweb\artbox\ecommerce\models\BrandLang;
  6 + use artweb\artbox\ecommerce\models\CategoryLang;
  7 + use artweb\artbox\ecommerce\models\Product;
  8 + use artweb\artbox\ecommerce\models\ProductLang;
  9 + use artweb\artbox\ecommerce\models\ProductVariant;
  10 + use artweb\artbox\ecommerce\models\ProductVariantLang;
  11 + use artweb\artbox\ecommerce\models\TaxGroup;
  12 + use yii\base\Object;
  13 + use yii\db\ActiveQuery;
  14 + use yii\db\Query;
  15 + use yii\helpers\ArrayHelper;
  16 +
  17 + class FilterHelper extends Object
28 18 {
29   - if (empty( static::$optionsList )) {
30   - return static::$optionsList = ArrayHelper::getColumn(
31   - TaxGroup::find()
32   - ->joinWith('lang')
33   - ->where([ 'is_filter' => 'TRUE' ])
34   - ->all(),
35   - 'lang.alias'
36   - );
37   - } else {
38   - return static::$optionsList;
39   - }
40 19  
41   - }
  20 + public static $optionsList = [];
42 21  
43   - /**
44   - * Return custom filter-option link
45   - *
46   - * @param array $filter
47   - * @param string $key
48   - * @param mixed $value
49   - * @param bool $remove
50   - *
51   - * @return array
52   - */
53   - public static function getFilterForOption(array $filter, string $key, $value, bool $remove = false)
54   - {
  22 + /**
  23 + * Get TaxGroups
  24 + *
  25 + * @return array
  26 + */
  27 + public static function optionsTemplate()
  28 + {
  29 + if (empty( static::$optionsList )) {
  30 + return static::$optionsList = ArrayHelper::getColumn(
  31 + TaxGroup::find()
  32 + ->joinWith('lang')
  33 + ->where([ 'is_filter' => 'TRUE' ])
  34 + ->all(),
  35 + 'lang.alias'
  36 + );
  37 + } else {
  38 + return static::$optionsList;
  39 + }
55 40  
56   - $optionsTemplate = self::optionsTemplate();
57   - array_unshift($optionsTemplate, "special", "brands");
  41 + }
  42 +
  43 + /**
  44 + * Return custom filter-option link
  45 + *
  46 + * @param array $filter
  47 + * @param string $key
  48 + * @param mixed $value
  49 + * @param bool $remove
  50 + *
  51 + * @return array
  52 + */
  53 + public static function getFilterForOption(array $filter, string $key, $value, bool $remove = false)
  54 + {
58 55  
59   - $result = $filter;
  56 + $optionsTemplate = self::optionsTemplate();
  57 + array_unshift($optionsTemplate, "special", "brands");
60 58  
61   - if (is_array($value)) {
62   - foreach ($value as $value_key => $value_items) {
63   - if (!is_array($value_items)) {
64   - $value_items = [ $value_items ];
65   - }
66   - foreach ($value_items as $value_item) {
67   - if ($remove && isset( $result[ $key ] ) && ( $i = array_search(
68   - $value_item,
69   - $result[ $key ][ $value_key ]
70   - ) ) !== false
71   - ) {
72   - unset( $result[ $key ][ $value_key ][ $i ] );
73   - if (empty( $result[ $key ][ $value_key ] )) {
74   - unset( $result[ $key ][ $value_key ] );
75   - }
76   - } else {
77   - if (!isset( $result[ $key ][ $value_key ] ) || array_search(
  59 + $result = $filter;
  60 +
  61 + if (is_array($value)) {
  62 + foreach ($value as $value_key => $value_items) {
  63 + if (!is_array($value_items)) {
  64 + $value_items = [ $value_items ];
  65 + }
  66 + foreach ($value_items as $value_item) {
  67 + if ($remove && isset( $result[ $key ] ) && ( $i = array_search(
78 68 $value_item,
79 69 $result[ $key ][ $value_key ]
80   - ) === false
  70 + ) ) !== false
81 71 ) {
82   - $result[ $key ][ $value_key ][] = $value_item;
  72 + unset( $result[ $key ][ $value_key ][ $i ] );
  73 + if (empty( $result[ $key ][ $value_key ] )) {
  74 + unset( $result[ $key ][ $value_key ] );
  75 + }
  76 + } else {
  77 + if (!isset( $result[ $key ][ $value_key ] ) || array_search(
  78 + $value_item,
  79 + $result[ $key ][ $value_key ]
  80 + ) === false
  81 + ) {
  82 + $result[ $key ][ $value_key ][] = $value_item;
  83 + }
83 84 }
84 85 }
85 86 }
86   - }
87   - } else {
88   - if ($remove && isset( $result[ $key ] ) && ( $i = array_search($value, $result[ $key ]) ) !== false) {
89   - unset( $result[ $key ][ $i ] );
90   - if (empty( $result[ $key ] )) {
91   - unset( $result[ $key ] );
92   - }
93 87 } else {
94   - if (!isset( $result[ $key ] ) || array_search($value, $result[ $key ]) === false) {
95   - $result[ $key ][] = $value;
  88 + if ($remove && isset( $result[ $key ] ) && ( $i = array_search($value, $result[ $key ]) ) !== false) {
  89 + unset( $result[ $key ][ $i ] );
  90 + if (empty( $result[ $key ] )) {
  91 + unset( $result[ $key ] );
  92 + }
  93 + } else {
  94 + if (!isset( $result[ $key ] ) || array_search($value, $result[ $key ]) === false) {
  95 + $result[ $key ][] = $value;
  96 + }
96 97 }
97 98 }
98   - }
99 99  
100   - $filterView = [];
  100 + $filterView = [];
  101 +
  102 + foreach ($optionsTemplate as $optionKey) {
  103 + if (isset( $result[ $optionKey ] )) {
  104 + $filterView[ $optionKey ] = $result[ $optionKey ];
  105 + }
101 106  
102   - foreach ($optionsTemplate as $optionKey) {
103   - if (isset( $result[ $optionKey ] )) {
104   - $filterView[ $optionKey ] = $result[ $optionKey ];
105 107 }
106 108  
  109 + return $filterView;
107 110 }
108 111  
109   - return $filterView;
110   - }
111 112  
112 113  
  114 + /**
  115 + * select options for product variants with selected category
  116 + *
  117 + * @param integer $categoryId
  118 + * @param integer $langId
  119 + * @return mixed
  120 + */
  121 + public static function getProductVariantOptions($categoryId,$langId){
113 122  
  123 + $cacheKey = [
  124 + 'OptionsForFilter',
  125 + 'categoryId' => $categoryId,
  126 + 'langId' =>$langId
  127 + ];
  128 + if (!$OptionsForFilter = \Yii::$app->cache->get($cacheKey)) {
  129 + $OptionsForFilter = ( new Query() )->distinct()->select('tax_group_lang.alias')
  130 + ->from('product_variant_option')
  131 + ->innerJoin(
  132 + 'tax_option',
  133 + 'product_variant_option.option_id = tax_option.id'
  134 + )
  135 + ->innerJoin(
  136 + 'tax_group',
  137 + 'tax_group.id = tax_option.tax_group_id'
  138 + )
  139 + ->innerJoin(
  140 + 'tax_group_lang',
  141 + 'tax_group_lang.tax_group_id = tax_group.id'
  142 + )
  143 + ->innerJoin(
  144 + 'tax_group_to_category',
  145 + 'tax_group_to_category.tax_group_id = tax_group.id'
  146 + )
  147 + ->where([
  148 + 'tax_group_lang.language_id' => $langId,
  149 + 'tax_group_to_category.category_id' => $categoryId,
  150 + 'tax_group.is_filter' => true
  151 + ])->all();
  152 + $OptionsForFilter = ArrayHelper::getColumn($OptionsForFilter,'alias');
  153 + \Yii::$app->cache->set($cacheKey, $OptionsForFilter, 3600 * 24);
  154 + }
  155 +
  156 + return $OptionsForFilter;
  157 + }
114 158  
115 159  
116   - public static function setNewQueryParams(ActiveQuery $query, array $params)
117   - {
118   - $last_query = null;
119   - foreach ($params as $key => $param) {
120   - switch ($key) {
121   - case 'special':
122   - self::filterSpecial($param, $query);
123   - break;
124   - case 'brands':
125   - self::filterBrands($param, $query);
126   - break;
127   - case 'keywords':
128   - self::filterKeywords($param, $query);
129   - break;
130   - case 'prices':
131   - self::filterPrices($param, $query);
132   - break;
133   - default:
134   - self::filterNewOptions($key, $param, $query);
135   - break;
  160 + /**
  161 + * Fill query with filter conditions
  162 + *
  163 + * @param ActiveQuery $query
  164 + * @param array $params
  165 + * @param integer $categoryId
  166 + * @param integer $langId
  167 + */
  168 + public static function setQueryParams(ActiveQuery $query, array $params, $categoryId, $langId)
  169 + {
  170 + $last_query = null;
  171 + $productVariantOptions = self::getProductVariantOptions($categoryId,$langId);
  172 + foreach ($params as $key => $param) {
  173 + switch ($key) {
  174 + case 'special':
  175 + unset($params[$key]);
  176 + self::filterSpecial($param, $query);
  177 + break;
  178 + case 'brands':
  179 + unset($params[$key]);
  180 + self::filterBrands($param, $query);
  181 + break;
  182 + case 'keywords':
  183 + unset($params[$key]);
  184 + self::filterKeywords($param, $query);
  185 + break;
  186 + case 'prices':
  187 + unset($params[$key]);
  188 + self::filterPrices($param, $query);
  189 + break;
  190 +
  191 + }
136 192 }
  193 + if(!empty($params)){
  194 + self::filterOptions($params, $productVariantOptions, $query,$langId);
  195 + }
  196 +
137 197 }
138   - }
139 198  
140 199  
141   - /**
142   - * @param $key
143   - * @param array $param
144   - * @param ActiveQuery $query
145   - */
146   - private static function filterNewOptions($key, array $param, &$query)
147   - {
148   - $query->andWhere(
149   - 'product.id IN (
150   - SELECT DISTINCT products
151   - FROM (
152   - SELECT id AS products FROM product WHERE id IN(
153   - SELECT product_id FROM product_option
154   - INNER JOIN tax_option ON tax_option.id = product_option.option_id
155   - INNER JOIN tax_group ON tax_group.id = tax_option.tax_group_id
156   - INNER JOIN tax_group_lang ON tax_group.id = tax_group_lang.tax_group_id
157   - INNER JOIN tax_option_lang ON tax_option.id = tax_option_lang.tax_option_id
158   - WHERE tax_group_lang.alias = \''. $key .'\' AND tax_option_lang.alias IN (\'' . implode('\',\'', $param) . '\'))
159   - OR id IN (
160   - (SELECT product_id AS products
161   - FROM product_variant_option
162   - INNER JOIN product_variant ON product_variant_option.product_variant_id = product_variant.id
163   - INNER JOIN tax_option ON tax_option.id = product_variant_option.option_id
164   - INNER JOIN tax_group ON tax_group.id = tax_option.tax_group_id
165   - INNER JOIN tax_group_lang ON tax_group.id = tax_group_lang.tax_group_id
166   - INNER JOIN tax_option_lang ON tax_option.id = tax_option_lang.tax_option_id
167   - WHERE tax_group_lang.alias = \''. $key .'\' AND tax_option_lang.alias IN (\'' . implode('\',\'', $param) . '\'))
168   - )
169   - ) AS table_name
170   - )'
171   - );
172 200  
  201 + /**
  202 + * Tax Option filter
  203 + *
  204 + * @param string[] $params
  205 + * @param string[] $productVariantOptions
  206 + * @param \yii\db\Query|null $query
  207 + * @param integer $langId
  208 + * @param bool $in_stock
  209 + *
  210 + * @return \yii\db\Query
  211 + */
  212 + private static function filterOptions(array $params,$productVariantOptions, Query &$query = null, $langId, bool $in_stock = true)
  213 + {
  214 + $variant_query = ( new Query() )->distinct()
  215 + ->select('product_variant.product_id as products')
  216 + ->from('product_variant');
  217 + $variantSearch = false;
  218 + foreach ($params as $key=>$param){
  219 + if(in_array($key, $productVariantOptions)){
  220 + $variantSearch = true;
  221 + unset($params[$key]);
  222 + $product_variant_id = ( new Query() )->distinct()->select('product_variant_option.product_variant_id as id')
  223 + ->from('product_variant_option')
  224 + ->innerJoin(
  225 + 'tax_option',
  226 + 'tax_option.id = product_variant_option.option_id'
  227 + )
  228 + ->innerJoin(
  229 + 'tax_option_lang',
  230 + 'tax_option_lang.tax_option_id = tax_option.id'
  231 + )
  232 + ->andWhere([ 'tax_option_lang.alias' => $param ])
  233 + ->andWhere([ 'tax_option_lang.language_id' => $langId ]);
  234 + $variant_query->andWhere(['product_variant.id'=>$product_variant_id]);
  235 + }
173 236  
174   - }
  237 + }
175 238  
  239 + if($variantSearch){
  240 + if($in_stock) {
  241 + $variant_query->andWhere(['!=', 'product_variant.stock', 0]);
  242 + }
  243 +
  244 +
  245 + $query->andWhere([ 'product.id' => $variant_query ]);
176 246  
177   - /**
178   - * Fill query with filter conditions
179   - *
180   - * @param ActiveQuery $query
181   - * @param array $params
182   - */
183   - public static function setQueryParams(ActiveQuery $query, array $params)
184   - {
185   - $last_query = null;
186   - foreach ($params as $key => $param) {
187   - switch ($key) {
188   - case 'special':
189   - self::filterSpecial($param, $query);
190   - break;
191   - case 'brands':
192   - self::filterBrands($param, $query);
193   - break;
194   - case 'keywords':
195   - self::filterKeywords($param, $query);
196   - break;
197   - case 'prices':
198   - self::filterPrices($param, $query);
199   - break;
200   - default:
201   - $last_query = self::filterOptions($param, $last_query);
202   - break;
203 247 }
204   - }
205   - // If tax option filters were provided filter query with them
206   - if (!empty( $last_query )) {
207   - $query->andWhere([ 'product.id' => $last_query ]);
208   - }
209   - }
210 248  
211 249  
212 250  
213   - /**
214   - * Tax Option filter
215   - *
216   - * @param string[] $params
217   - * @param \yii\db\Query|null $last_query
218   - * @param bool $in_stock
219   - *
220   - * @return \yii\db\Query
221   - */
222   - private static function filterOptions(array $params, Query $last_query = null, bool $in_stock = true): Query
223   - {
  251 + if(!empty($params)) {
  252 + $product_query = ( new Query() )->distinct()
  253 + ->select('product_option.product_id as products')
  254 + ->from('product_option')
  255 + ->innerJoin(
  256 + 'tax_option',
  257 + 'tax_option.id = product_option.option_id'
  258 + )
  259 + ->innerJoin(
  260 + 'tax_option_lang',
  261 + 'tax_option_lang.tax_option_id = tax_option.id'
  262 + );
  263 + foreach ($params as $key=>$param){
  264 + $product_query
  265 + ->andWhere([ 'tax_option_lang.alias' => $param ]);
  266 +
  267 + }
  268 + $query->andWhere([ 'tax_option_lang.language_id' => $langId ]);
  269 + $query->andWhere([ 'product.id' => $product_query ]);
  270 + }
  271 +
224 272  
225   - $variant_query = ( new Query() )->distinct()
226   - ->select('product_variant.product_id as products')
227   - ->from('product_variant_option')
228   - ->innerJoin(
229   - 'product_variant',
230   - 'product_variant_option.product_variant_id = product_variant.id'
231   - )
232   - ->innerJoin(
233   - 'tax_option',
234   - 'tax_option.id = product_variant_option.option_id'
235   - )
236   - ->innerJoin(
237   - 'tax_option_lang',
238   - 'tax_option_lang.tax_option_id = tax_option.id'
239   - )
240   - ->where([ 'tax_option_lang.alias' => $params ]);
241   - if($in_stock) {
242   - $variant_query->andWhere(['!=', 'product_variant.stock', 0]);
243   - }
244   - $product_query = ( new Query() )->distinct()
245   - ->select('product_option.product_id as products')
246   - ->from('product_option')
247   - ->innerJoin('tax_option', 'product_option.option_id = tax_option.id')
248   - ->innerJoin(
249   - 'tax_option_lang',
250   - 'tax_option_lang.tax_option_id = tax_option.id'
251   - )
252   - ->where(
253   - [ 'tax_option_lang.alias' => $params ]
254   - )
255   - ->union($variant_query);
256   - $query = ( new Query() )->select('products')
257   - ->from([ 'result_table' => $product_query ]);
258   - if (!empty( $last_query )) {
259   - $query->andWhere([ 'product.id' => $last_query ]);
260 273 }
261   - return $query;
262   - }
263 274  
264   - /**
265   - * Fill $query with special filters (used in Product)
266   - *
267   - * @param array $params
268   - * @param \yii\db\ActiveQuery $query
269   - */
270   - private static function filterSpecial(array $params, ActiveQuery $query)
271   - {
272   - $conditions = [];
  275 +
  276 +
273 277 /**
274   - * @var string $key
  278 + * Fill $query with special filters (used in Product)
  279 + *
  280 + * @param array $params
  281 + * @param \yii\db\ActiveQuery $query
275 282 */
276   - foreach ($params as $key => $param) {
277   - $conditions[] = [
278   - '=',
279   - Product::tableName() . '.' . $key,
280   - $param,
281   - ];
282   - }
283   - /* If 2 or more special conditions get all that satisfy at least one of them. */
284   - if (count($conditions) > 1) {
285   - array_unshift($conditions, 'or');
286   - } else {
287   - $conditions = $conditions[ 0 ];
  283 + private static function filterSpecial(array $params, ActiveQuery $query)
  284 + {
  285 + $conditions = [];
  286 + /**
  287 + * @var string $key
  288 + */
  289 + foreach ($params as $key => $param) {
  290 + $conditions[] = [
  291 + '=',
  292 + Product::tableName() . '.' . $key,
  293 + $param,
  294 + ];
  295 + }
  296 + /* If 2 or more special conditions get all that satisfy at least one of them. */
  297 + if (count($conditions) > 1) {
  298 + array_unshift($conditions, 'or');
  299 + } else {
  300 + $conditions = $conditions[ 0 ];
  301 + }
  302 + $query->andFilterWhere($conditions);
288 303 }
289   - $query->andFilterWhere($conditions);
290   - }
291 304  
292   - /**
293   - * Fill query with brands filter
294   - *
295   - * @param int[] $param
296   - * @param \yii\db\ActiveQuery $query
297   - */
298   - private static function filterBrands(array $param, ActiveQuery $query)
299   - {
300   - $query->andFilterWhere([ Product::tableName() . '.brand_id' => $param ]);
301   - }
  305 + /**
  306 + * Fill query with brands filter
  307 + *
  308 + * @param int[] $param
  309 + * @param \yii\db\ActiveQuery $query
  310 + */
  311 + private static function filterBrands(array $param, ActiveQuery $query)
  312 + {
  313 + $query->andFilterWhere([ Product::tableName() . '.brand_id' => $param ]);
  314 + }
302 315  
303   - /**
304   - * Fill query with keywords filter
305   - *
306   - * @param array $params
307   - * @param \yii\db\ActiveQuery $query
308   - */
309   - private static function filterKeywords(array $params, ActiveQuery $query)
310   - {
311   - $conditions = [];
312   - if (!empty( $params )) {
313   - if (!is_array($params)) {
314   - $params = [ $params ];
315   - }
316   - /**
317   - * @var string $param Inputed keyword
318   - */
319   - foreach ($params as $param) {
320   -
321   - if(iconv_strlen($param) >= 3 && $param != preg_match ('/^20[\d]{2}$/',$param, $matches)){
322   - $conditions[] = [
323   - 'or',
324   - [
325   - 'ilike',
326   - ProductLang::tableName() . '.title',
327   - $param,
328   - ],
329   - [
330   - 'ilike',
331   - BrandLang::tableName() . '.title',
332   - $param,
333   - ],
334   - [
335   - 'ilike',
336   - CategoryLang::tableName() . '.title',
337   - $param,
338   - ],
339   - [
340   - 'ilike',
341   - ProductVariantLang::tableName() . '.title',
342   - $param,
343   - ],
344   - [
345   - 'ilike',
346   - ProductVariant::tableName() . '.sku',
347   - $param,
348   - ]
349   -
350   - ];
  316 + /**
  317 + * Fill query with keywords filter
  318 + *
  319 + * @param array $params
  320 + * @param \yii\db\ActiveQuery $query
  321 + */
  322 + private static function filterKeywords(array $params, ActiveQuery $query)
  323 + {
  324 + $conditions = [];
  325 + if (!empty( $params )) {
  326 + if (!is_array($params)) {
  327 + $params = [ $params ];
351 328 }
  329 + /**
  330 + * @var string $param Inputed keyword
  331 + */
  332 + foreach ($params as $param) {
  333 +
  334 + if(iconv_strlen($param) >= 3){
  335 + $conditions[] = [
  336 + 'or',
  337 + [
  338 + 'ilike',
  339 + ProductLang::tableName() . '.title',
  340 + $param,
  341 + ],
  342 + [
  343 + 'ilike',
  344 + BrandLang::tableName() . '.title',
  345 + $param,
  346 + ],
  347 + [
  348 + 'ilike',
  349 + CategoryLang::tableName() . '.title',
  350 + $param,
  351 + ],
  352 + [
  353 + 'ilike',
  354 + ProductVariantLang::tableName() . '.title',
  355 + $param,
  356 + ],
  357 + [
  358 + 'ilike',
  359 + ProductVariant::tableName() . '.sku',
  360 + $param,
  361 + ]
  362 +
  363 + ];
  364 + }
352 365  
353 366  
  367 + }
354 368 }
  369 + if (count($conditions) > 1) {
  370 + array_unshift($conditions, 'or');
  371 + } else {
  372 + $conditions = $conditions[ 0 ];
  373 + }
  374 + $query->andFilterWhere($conditions);
355 375 }
356   - if (count($conditions) > 1) {
357   - array_unshift($conditions, 'or');
358   - } else {
359   - $conditions = $conditions[ 0 ];
360   - }
361   - $query->andFilterWhere($conditions);
362   - }
363 376  
364   - /**
365   - * Fill query with price limits filter
366   - *
367   - * @param array $params
368   - * @param \yii\db\ActiveQuery $query
369   - */
370   - private static function filterPrices(array $params, ActiveQuery $query)
371   - {
372   - $conditions = [];
373   - if (!empty( $params[ 'min' ] ) && $params[ 'min' ] > 0) {
374   - $conditions[] = [
375   - '>=',
376   - ProductVariant::tableName() . '.price',
377   - $params[ 'min' ],
378   - ];
379   - }
380   - if (!empty( $params[ 'max' ] ) && $params[ 'max' ] > 0) {
381   - $conditions[] = [
382   - '<=',
383   - ProductVariant::tableName() . '.price',
384   - $params[ 'max' ],
385   - ];
386   - }
387   - if (count($conditions) > 1) {
388   - array_unshift($conditions, 'and');
389   - } else {
390   - $conditions = $conditions[ 0 ];
  377 + /**
  378 + * Fill query with price limits filter
  379 + *
  380 + * @param array $params
  381 + * @param \yii\db\ActiveQuery $query
  382 + */
  383 + private static function filterPrices(array $params, ActiveQuery $query)
  384 + {
  385 + $conditions = [];
  386 + if (!empty( $params[ 'min' ] ) && $params[ 'min' ] > 0) {
  387 + $conditions[] = [
  388 + '>=',
  389 + ProductVariant::tableName() . '.price',
  390 + $params[ 'min' ],
  391 + ];
  392 + }
  393 + if (!empty( $params[ 'max' ] ) && $params[ 'max' ] > 0) {
  394 + $conditions[] = [
  395 + '<=',
  396 + ProductVariant::tableName() . '.price',
  397 + $params[ 'max' ],
  398 + ];
  399 + }
  400 + if (count($conditions) > 1) {
  401 + array_unshift($conditions, 'and');
  402 + } else {
  403 + $conditions = $conditions[ 0 ];
  404 + }
  405 + $query->andFilterWhere($conditions);
391 406 }
392   - $query->andFilterWhere($conditions);
393   - }
394 407  
395   -}
  408 + }
396 409  
397 410 \ No newline at end of file
... ...
models/ProductFrontendSearch.php
... ... @@ -4,6 +4,7 @@
4 4  
5 5 use artweb\artbox\ecommerce\helpers\FilterHelper;
6 6 use artweb\artbox\ecommerce\models\Category;
  7 + use artweb\artbox\language\models\Language;
7 8 use yii\base\Model;
8 9 use yii\data\ActiveDataProvider;
9 10 use yii\data\ArrayDataProvider;
... ... @@ -117,22 +118,18 @@
117 118 return $dataProvider;
118 119 }
119 120  
120   - public function getSearchQuery($category = null, $params = [], $in_stock = true)
  121 +
  122 + /**
  123 + * @param Category $category
  124 + * @param array $params
  125 + * @param bool $in_stock
  126 + * @return mixed
  127 + */
  128 + public function getSearchQuery($category, $params = [], $in_stock = true)
121 129 {
122 130  
123   - if (!empty( $category )) {
124   - /** @var ActiveQuery $query */
125   - /**@var Category $category * */
126   - $query = $category->getProducts();
  131 + $query = $category->getProducts();
127 132  
128   - } else {
129   - $query = Product::find()
130   - ->joinWith(
131   - [
132   - 'category.lang',
133   - ]
134   - );
135   - }
136 133  
137 134 $query->select([ 'product.*' ]);
138 135 $query->joinWith(
... ... @@ -176,7 +173,8 @@
176 173 ]
177 174 );
178 175  
179   - FilterHelper::setQueryParams($query, $params);
  176 + $lang = Language::getCurrent();
  177 + FilterHelper::setQueryParams($query, $params, $category->id, $lang->id);
180 178 return $query;
181 179 }
182 180  
... ... @@ -202,7 +200,8 @@
202 200 // Price filter fix
203 201 unset( $params[ 'prices' ] );
204 202  
205   - FilterHelper::setQueryParams($query, $params);
  203 + $lang = Language::getCurrent();
  204 + FilterHelper::setQueryParams($query, $params, $category->id, $lang->id);
206 205 $query->andWhere(
207 206 [
208 207 '>=',
... ...