diff --git a/helpers/FilterHelper.php b/helpers/FilterHelper.php index 16d95a6..a046eb7 100755 --- a/helpers/FilterHelper.php +++ b/helpers/FilterHelper.php @@ -190,7 +190,10 @@ } } - self::filterOptions($params, $productVariantOptions, $query); + if(!empty($params)){ + self::filterOptions($params, $productVariantOptions, $query); + } + } @@ -210,9 +213,10 @@ $variant_query = ( new Query() )->distinct() ->select('product_variant.product_id as products') ->from('product_variant'); - + $variantSearch = false; foreach ($params as $key=>$param){ if(in_array($key, $productVariantOptions)){ + $variantSearch = true; unset($params[$key]); $product_variant_id = ( new Query() )->distinct()->select('product_variant_option.product_variant_id as id') ->from('product_variant_option') @@ -239,38 +243,47 @@ } + if($variantSearch){ + if($in_stock) { + $variant_query->andWhere(['!=', 'product_variant.stock', 0]); + } + + + $query->andWhere([ 'product.id' => $variant_query ]); - 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', - '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' - ); - foreach ($params as $key=>$param){ - $product_query - ->where([ 'tax_group_lang.alias' => $key ]) - ->andWhere([ 'tax_option_lang.alias' => $param ]); + + + if(!empty($params)) { + $product_query = ( new Query() )->distinct() + ->select('product_option.product_id as products') + ->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' + ); + foreach ($params as $key=>$param){ + $product_query + ->where([ 'tax_group_lang.alias' => $key ]) + ->andWhere([ 'tax_option_lang.alias' => $param ]); + + } + $query->andWhere([ 'product.id' => $product_query ]); } - $query->andWhere([ 'product.id' => $product_query ]); - $query->andWhere([ 'product.id' => $variant_query ]); } -- libgit2 0.21.4