From c7d997a91f5dae14617545be1a9cdf91e4f9e2be Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 5 Dec 2016 23:49:47 +0200 Subject: [PATCH] add variantSku --- helpers/FilterHelper.php | 61 +++++++++++++++++++++++++++++++++++-------------------------- models/ProductFrontendSearch.php | 29 ++++++++++++++--------------- 2 files changed, 49 insertions(+), 41 deletions(-) diff --git a/helpers/FilterHelper.php b/helpers/FilterHelper.php index a9708f4..16d95a6 100755 --- a/helpers/FilterHelper.php +++ b/helpers/FilterHelper.php @@ -119,32 +119,41 @@ * @return mixed */ public static function getProductVariantOptions($categoryId,$langId){ - $result = \Yii::$app->db->cache(function () use($categoryId,$langId) { - return ( new Query() )->distinct()->select('tax_group_lang.alias') - ->from('product_variant_option') - ->innerJoin( - 'tax_option', - 'product_variant_option.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' - ) - ->innerJoin( - 'tax_group_to_category', - 'tax_group_to_category.tax_group_id = tax_group.id' - ) - ->where([ - 'tax_group_lang.language_id' => $langId, - 'tax_group_to_category.category_id' => $categoryId, - 'tax_group.is_filter' => true - ])->all(); - },60*60*24); - return ArrayHelper::getColumn($result,'alias'); + + $cacheKey = [ + 'OptionsForFilter', + 'categoryId' => $categoryId, + 'langId' =>$langId + ]; + if (!$OptionsForFilter = \Yii::$app->cache->get($cacheKey)) { + $OptionsForFilter = ( new Query() )->distinct()->select('tax_group_lang.alias') + ->from('product_variant_option') + ->innerJoin( + 'tax_option', + 'product_variant_option.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' + ) + ->innerJoin( + 'tax_group_to_category', + 'tax_group_to_category.tax_group_id = tax_group.id' + ) + ->where([ + 'tax_group_lang.language_id' => $langId, + 'tax_group_to_category.category_id' => $categoryId, + 'tax_group.is_filter' => true + ])->all(); + $OptionsForFilter = ArrayHelper::getColumn($OptionsForFilter,'alias'); + \Yii::$app->cache->set($cacheKey, $OptionsForFilter, 3600 * 24); + } + + return $OptionsForFilter; } diff --git a/models/ProductFrontendSearch.php b/models/ProductFrontendSearch.php index d77832c..cd13d35 100755 --- a/models/ProductFrontendSearch.php +++ b/models/ProductFrontendSearch.php @@ -4,6 +4,7 @@ use artweb\artbox\ecommerce\helpers\FilterHelper; use artweb\artbox\ecommerce\models\Category; + use artweb\artbox\language\models\Language; use yii\base\Model; use yii\data\ActiveDataProvider; use yii\data\ArrayDataProvider; @@ -117,22 +118,18 @@ return $dataProvider; } - public function getSearchQuery($category = null, $params = [], $in_stock = true) + + /** + * @param Category $category + * @param array $params + * @param bool $in_stock + * @return mixed + */ + public function getSearchQuery($category, $params = [], $in_stock = true) { - if (!empty( $category )) { - /** @var ActiveQuery $query */ - /**@var Category $category * */ - $query = $category->getProducts(); + $query = $category->getProducts(); - } else { - $query = Product::find() - ->joinWith( - [ - 'category.lang', - ] - ); - } $query->select([ 'product.*' ]); $query->joinWith( @@ -176,7 +173,8 @@ ] ); - FilterHelper::setQueryParams($query, $params); + $lang = Language::getCurrent(); + FilterHelper::setQueryParams($query, $params, $category->id, $lang->id); return $query; } @@ -202,7 +200,8 @@ // Price filter fix unset( $params[ 'prices' ] ); - FilterHelper::setQueryParams($query, $params); + $lang = Language::getCurrent(); + FilterHelper::setQueryParams($query, $params, $category->id, $lang->id); $query->andWhere( [ '>=', -- libgit2 0.21.4