diff --git a/helpers/FilterHelper.php b/helpers/FilterHelper.php index 4b1fec7..f073a15 100755 --- a/helpers/FilterHelper.php +++ b/helpers/FilterHelper.php @@ -108,7 +108,9 @@ return $filterView; } - + + + /** * Fill query with filter conditions * @@ -121,28 +123,33 @@ foreach ($params as $key => $param) { switch ($key) { case 'special': + unset($params[$key]); self::filterSpecial($param, $query); break; case 'brands': + unset($params[$key]); self::filterBrands($param, $query); break; case 'keywords': + unset($params[$key]); self::filterKeywords($param, $query); break; case 'prices': + unset($params[$key]); self::filterPrices($param, $query); break; - default: - $last_query = self::filterOptions($param, $last_query); - break; } } + $last_query = self::filterOptions($params, $last_query); // If tax option filters were provided filter query with them if (!empty( $last_query )) { $query->andWhere([ 'product.id' => $last_query ]); } } - + + + + /** * Tax Option filter * @@ -160,31 +167,65 @@ ->innerJoin( 'product_variant', 'product_variant_option.product_variant_id = product_variant.id' - ) - ->innerJoin( - 'tax_option', - 'tax_option.id = product_variant_option.option_id' - ) - ->innerJoin( - 'tax_option_lang', - 'tax_option_lang.tax_option_id = tax_option.id' - ) - ->where([ 'tax_option_lang.alias' => $params ]); + ); + + foreach ($params as $key=>$param){ + $product_variant_id = ( new Query() )->distinct()->select('product_variant_option.product_variant_id as id') + ->from('product_variant_option') + ->innerJoin( + 'tax_option', + 'tax_option.id = product_variant_option.option_id' + ) + ->innerJoin( + 'tax_option_lang', + 'tax_option_lang.tax_option_id = tax_option.id' + ) + ->innerJoin( + 'tax_group', + 'tax_group.id = tax_option.tax_group_id' + ) + ->innerJoin( + 'tax_group_lang', + 'tax_group_lang.tax_group_id = tax_group.id' + ) + ->where([ 'tax_group_lang.alias' => $key ]) + ->andWhere([ 'tax_option_lang.alias' => $param ]); + $variant_query->andWhere(['product_variant_option.product_variant_id'=>$product_variant_id]); + + } + + if($in_stock) { $variant_query->andWhere(['!=', 'product_variant.stock', 0]); } $product_query = ( new Query() )->distinct() ->select('product_option.product_id as products') - ->from('product_option') - ->innerJoin('tax_option', 'product_option.option_id = tax_option.id') - ->innerJoin( - 'tax_option_lang', - 'tax_option_lang.tax_option_id = tax_option.id' - ) - ->where( - [ 'tax_option_lang.alias' => $params ] - ) - ->union($variant_query); + ->from('product_option'); + foreach ($params as $key=>$param){ + $product_id = ( new Query() )->distinct()->select('product_option.product_id as id') + ->from('product_option') + ->innerJoin( + 'tax_option', + 'tax_option.id = product_option.option_id' + ) + ->innerJoin( + 'tax_option_lang', + 'tax_option_lang.tax_option_id = tax_option.id' + ) + ->innerJoin( + 'tax_group', + 'tax_group.id = tax_option.tax_group_id' + ) + ->innerJoin( + 'tax_group_lang', + 'tax_group_lang.tax_group_id = tax_group.id' + ) + ->where([ 'tax_group_lang.alias' => $key ]) + ->andWhere([ 'tax_option_lang.alias' => $param ]); + $product_query->andWhere(['product_option.product_id'=>$product_id]); + + } + $product_query->union($variant_query); $query = ( new Query() )->select('products') ->from([ 'result_table' => $product_query ]); if (!empty( $last_query )) { -- libgit2 0.21.4