Commit c7d997a91f5dae14617545be1a9cdf91e4f9e2be
1 parent
4ace1a69
add variantSku
Showing
2 changed files
with
49 additions
and
41 deletions
Show diff stats
helpers/FilterHelper.php
@@ -119,32 +119,41 @@ | @@ -119,32 +119,41 @@ | ||
119 | * @return mixed | 119 | * @return mixed |
120 | */ | 120 | */ |
121 | public static function getProductVariantOptions($categoryId,$langId){ | 121 | public static function getProductVariantOptions($categoryId,$langId){ |
122 | - $result = \Yii::$app->db->cache(function () use($categoryId,$langId) { | ||
123 | - return ( new Query() )->distinct()->select('tax_group_lang.alias') | ||
124 | - ->from('product_variant_option') | ||
125 | - ->innerJoin( | ||
126 | - 'tax_option', | ||
127 | - 'product_variant_option.option_id = tax_option.id' | ||
128 | - ) | ||
129 | - ->innerJoin( | ||
130 | - 'tax_group', | ||
131 | - 'tax_group.id = tax_option.tax_group_id' | ||
132 | - ) | ||
133 | - ->innerJoin( | ||
134 | - 'tax_group_lang', | ||
135 | - 'tax_group_lang.tax_group_id = tax_group.id' | ||
136 | - ) | ||
137 | - ->innerJoin( | ||
138 | - 'tax_group_to_category', | ||
139 | - 'tax_group_to_category.tax_group_id = tax_group.id' | ||
140 | - ) | ||
141 | - ->where([ | ||
142 | - 'tax_group_lang.language_id' => $langId, | ||
143 | - 'tax_group_to_category.category_id' => $categoryId, | ||
144 | - 'tax_group.is_filter' => true | ||
145 | - ])->all(); | ||
146 | - },60*60*24); | ||
147 | - return ArrayHelper::getColumn($result,'alias'); | 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; | ||
148 | } | 157 | } |
149 | 158 | ||
150 | 159 |
models/ProductFrontendSearch.php
@@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
4 | 4 | ||
5 | use artweb\artbox\ecommerce\helpers\FilterHelper; | 5 | use artweb\artbox\ecommerce\helpers\FilterHelper; |
6 | use artweb\artbox\ecommerce\models\Category; | 6 | use artweb\artbox\ecommerce\models\Category; |
7 | + use artweb\artbox\language\models\Language; | ||
7 | use yii\base\Model; | 8 | use yii\base\Model; |
8 | use yii\data\ActiveDataProvider; | 9 | use yii\data\ActiveDataProvider; |
9 | use yii\data\ArrayDataProvider; | 10 | use yii\data\ArrayDataProvider; |
@@ -117,22 +118,18 @@ | @@ -117,22 +118,18 @@ | ||
117 | return $dataProvider; | 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 | $query->select([ 'product.*' ]); | 134 | $query->select([ 'product.*' ]); |
138 | $query->joinWith( | 135 | $query->joinWith( |
@@ -176,7 +173,8 @@ | @@ -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 | return $query; | 178 | return $query; |
181 | } | 179 | } |
182 | 180 | ||
@@ -202,7 +200,8 @@ | @@ -202,7 +200,8 @@ | ||
202 | // Price filter fix | 200 | // Price filter fix |
203 | unset( $params[ 'prices' ] ); | 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 | $query->andWhere( | 205 | $query->andWhere( |
207 | [ | 206 | [ |
208 | '>=', | 207 | '>=', |