From 4fd39cf0b220d4e3c6488df9fe7f5f8412b7d0f6 Mon Sep 17 00:00:00 2001 From: yarik Date: Fri, 2 Dec 2016 19:34:05 +0200 Subject: [PATCH] Query fix in_stock added --- helpers/FilterHelper.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/helpers/FilterHelper.php b/helpers/FilterHelper.php index d763336..4b1fec7 100755 --- a/helpers/FilterHelper.php +++ b/helpers/FilterHelper.php @@ -142,16 +142,17 @@ $query->andWhere([ 'product.id' => $last_query ]); } } - + /** * Tax Option filter * * @param string[] $params * @param \yii\db\Query|null $last_query + * @param bool $in_stock * - * @return Query + * @return \yii\db\Query */ - private static function filterOptions(array $params, Query $last_query = null): Query + private static function filterOptions(array $params, Query $last_query = null, bool $in_stock = true): Query { $variant_query = ( new Query() )->distinct() ->select('product_variant.product_id as products') @@ -169,6 +170,9 @@ 'tax_option_lang.tax_option_id = tax_option.id' ) ->where([ 'tax_option_lang.alias' => $params ]); + 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') -- libgit2 0.21.4