Commit 5fd5b9ca32ded3f4f684a9d157643a2f5364974e
1 parent
29c20011
big commti
Showing
2 changed files
with
46 additions
and
99 deletions
Show diff stats
common/modules/product/models/Category.php
@@ -197,51 +197,53 @@ class Category extends \yii\db\ActiveRecord | @@ -197,51 +197,53 @@ class Category extends \yii\db\ActiveRecord | ||
197 | return true; | 197 | return true; |
198 | } | 198 | } |
199 | public function getActiveFilters() { | 199 | public function getActiveFilters() { |
200 | + return Category::getDb()->cache(function(){ | ||
201 | + $query1 = (new Query()) | ||
202 | + ->distinct() | ||
203 | + ->select([ | ||
204 | + 'option_id' | ||
205 | + ]) | ||
206 | + ->from('tax_option') | ||
207 | + ->innerJoin('product_variant_option', 'tax_option.tax_option_id = product_variant_option.option_id') | ||
208 | + ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id') | ||
209 | + ->innerJoin('product_variant', 'product_variant.product_variant_id = product_variant_option.product_variant_id') | ||
210 | + ->innerJoin('product', 'product.product_id = product_variant.product_id') | ||
211 | + ->innerJoin('product_category', 'product_category.product_id = product.product_id') | ||
212 | + ->innerJoin('tax_group_to_category', 'tax_group.tax_group_id = tax_group_to_category.tax_group_id') | ||
213 | + ->where(['product_category.category_id' => $this->category_id, 'tax_group.is_filter' => TRUE,'tax_group_to_category.category_id'=>$this->category_id]) | ||
214 | + ->andWhere(['!=', 'product_variant.status', 1]); | ||
215 | + | ||
216 | + $query2 = (new Query()) | ||
217 | + ->distinct() | ||
218 | + ->select([ | ||
219 | + 'option_id' | ||
220 | + ]) | ||
221 | + ->from('tax_option') | ||
222 | + ->innerJoin('product_option', 'tax_option.tax_option_id = product_option.option_id') | ||
223 | + ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id') | ||
224 | + ->innerJoin('product', 'product.product_id = product_option.product_id') | ||
225 | + ->innerJoin('product_category', 'product_category.product_id = product.product_id') | ||
226 | + ->innerJoin('product_variant', 'product_variant.product_id = product.product_id') | ||
227 | + ->innerJoin('tax_group_to_category', 'tax_group.tax_group_id = tax_group_to_category.tax_group_id') | ||
228 | + ->where(['product_category.category_id' => $this->category_id, 'tax_group.is_filter' => TRUE,'tax_group_to_category.category_id'=>$this->category_id]) | ||
229 | + ->andWhere(['!=', 'product_variant.status', 1]); | ||
230 | + $query3 = (new Query()) | ||
231 | + ->select([ | ||
232 | + 'tax_option.*', | ||
233 | + 'tax_group.*', | ||
234 | + 'tax_option.alias as option_alias', | ||
235 | + 'tax_group.alias as group_alias', | ||
236 | + 'tax_option.name as value', | ||
237 | + 'tax_option.sort AS tax_option_sort', | ||
238 | + 'tax_group.sort AS tax_group_sort', | ||
239 | + ]) | ||
240 | + ->from(['tax_option' ]) | ||
241 | + ->where(['tax_option.tax_option_id'=>$query1->union($query2)]) | ||
242 | + ->innerJoin('tax_group','tax_group.tax_group_id = tax_option.tax_group_id') | ||
243 | + ->orderBy('tax_option.sort, tax_group.sort'); | ||
244 | + return $query3->all(); | ||
245 | + }, 3600*24); | ||
200 | 246 | ||
201 | - $query1 = (new Query()) | ||
202 | - ->distinct() | ||
203 | - ->select([ | ||
204 | - 'option_id' | ||
205 | - ]) | ||
206 | - ->from('tax_option') | ||
207 | - ->innerJoin('product_variant_option', 'tax_option.tax_option_id = product_variant_option.option_id') | ||
208 | - ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id') | ||
209 | - ->innerJoin('product_variant', 'product_variant.product_variant_id = product_variant_option.product_variant_id') | ||
210 | - ->innerJoin('product', 'product.product_id = product_variant.product_id') | ||
211 | - ->innerJoin('product_category', 'product_category.product_id = product.product_id') | ||
212 | - ->innerJoin('tax_group_to_category', 'tax_group.tax_group_id = tax_group_to_category.tax_group_id') | ||
213 | - ->where(['product_category.category_id' => $this->category_id, 'tax_group.is_filter' => TRUE,'tax_group_to_category.category_id'=>$this->category_id]) | ||
214 | - ->andWhere(['!=', 'product_variant.status', 1]); | ||
215 | - | ||
216 | - $query2 = (new Query()) | ||
217 | - ->distinct() | ||
218 | - ->select([ | ||
219 | - 'option_id' | ||
220 | - ]) | ||
221 | - ->from('tax_option') | ||
222 | - ->innerJoin('product_option', 'tax_option.tax_option_id = product_option.option_id') | ||
223 | - ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id') | ||
224 | - ->innerJoin('product', 'product.product_id = product_option.product_id') | ||
225 | - ->innerJoin('product_category', 'product_category.product_id = product.product_id') | ||
226 | - ->innerJoin('product_variant', 'product_variant.product_id = product.product_id') | ||
227 | - ->innerJoin('tax_group_to_category', 'tax_group.tax_group_id = tax_group_to_category.tax_group_id') | ||
228 | - ->where(['product_category.category_id' => $this->category_id, 'tax_group.is_filter' => TRUE,'tax_group_to_category.category_id'=>$this->category_id]) | ||
229 | - ->andWhere(['!=', 'product_variant.status', 1]); | ||
230 | - $query3 = (new Query()) | ||
231 | - ->select([ | ||
232 | - 'tax_option.*', | ||
233 | - 'tax_group.*', | ||
234 | - 'tax_option.alias as option_alias', | ||
235 | - 'tax_group.alias as group_alias', | ||
236 | - 'tax_option.name as value', | ||
237 | - 'tax_option.sort AS tax_option_sort', | ||
238 | - 'tax_group.sort AS tax_group_sort', | ||
239 | - ]) | ||
240 | - ->from(['tax_option' ]) | ||
241 | - ->where(['tax_option.tax_option_id'=>$query1->union($query2)]) | ||
242 | - ->innerJoin('tax_group','tax_group.tax_group_id = tax_option.tax_group_id') | ||
243 | - ->orderBy('tax_option.sort, tax_group.sort'); | ||
244 | - return $query3->all(); | ||
245 | } | 247 | } |
246 | 248 | ||
247 | public function getTaxGroupsForMenu() | 249 | public function getTaxGroupsForMenu() |
frontend/models/ProductFrontendSearch.php
@@ -104,61 +104,6 @@ class ProductFrontendSearch extends Product { | @@ -104,61 +104,6 @@ class ProductFrontendSearch extends Product { | ||
104 | return $query; | 104 | return $query; |
105 | } | 105 | } |
106 | 106 | ||
107 | - public function optionsForCategory($category = null, $params = []) { | ||
108 | - $query = TaxOption::find() | ||
109 | - ->select([ | ||
110 | - TaxOption::tableName() .'.*', | ||
111 | - ]) | ||
112 | - ->leftJoin(ProductOption::tableName(), ProductOption::tableName() .'.option_id='. TaxOption::tableName() .'.tax_option_id') | ||
113 | - ->joinWith('taxGroup') | ||
114 | - ->where([TaxGroup::tableName() .'.is_filter' => true]); | ||
115 | - | ||
116 | - $query->innerJoin('product_variant', 'product_variant.product_id = '. ProductOption::tableName() .'.product_id'); | ||
117 | - $query->andWhere(['!=', 'product_variant.status', 1]); | ||
118 | - $query->groupBy(TaxOption::tableName() .'.tax_option_id'); | ||
119 | -// $query->having(['>', 'COUNT(product_variant.product_variant_id)', 0]); | ||
120 | - | ||
121 | - if (!empty($category)) { | ||
122 | - $query->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.product_id='. ProductOption::tableName() .'.product_id'); | ||
123 | - $query->andWhere([ProductCategory::tableName() .'.category_id' => $category->category_id]); | ||
124 | - } | ||
125 | - | ||
126 | - $query->orderBy(TaxOption::tableName() .'.sort', SORT_ASC); | ||
127 | - $query->limit(null); | ||
128 | - | ||
129 | -// $queryCount = ProductOption::find() | ||
130 | -// ->select(['COUNT('. ProductOption::tableName() .'.product_id)']) | ||
131 | -// ->where(ProductOption::tableName() .'.option_id = '. TaxOption::tableName() .'.tax_option_id'); | ||
132 | -// $queryCount->andWhere('(SELECT COUNT(pv.product_variant_id) FROM "product_variant" "pv" WHERE pv.stock != 0 AND pv.product_id = '. ProductOption::tableName() .'.product_id) > 0'); | ||
133 | -// if (!empty($category)) { | ||
134 | -// $queryCount->andWhere('(SELECT COUNT(pc.product_id) FROM product_category pc WHERE pc.product_id = '. ProductOption::tableName() .'.product_id AND pc.category_id = '. $category->category_id .') > 0'); | ||
135 | -// } | ||
136 | -// if (!empty($params['options'])) { | ||
137 | -// $queryCount->innerJoin('tax_option', 'tax_option.tax_option_id = product_option.option_id'); | ||
138 | -// $queryCount->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id'); | ||
139 | -// foreach ($params['options'] as $group => $options) { | ||
140 | -// $queryCount->andWhere([ | ||
141 | -// 'tax_group.alias' => $group, | ||
142 | -// 'tax_option.alias' => $options | ||
143 | -// ]); | ||
144 | -// } | ||
145 | -// } | ||
146 | -// if (!empty($params['brands'])) { | ||
147 | -// $queryCount->innerJoin(Product::tableName(), 'product.product_id='. ProductOption::tableName() .'.product_id'); | ||
148 | -// $queryCount->andWhere(['product.brand_id' => $params['brands']]); | ||
149 | -// } | ||
150 | -// if (!empty($params['prices'])) { | ||
151 | -// if ($params['prices']['min'] > 0) { | ||
152 | -// $queryCount->andWhere(['>=', 'pv.price', $params['prices']['min']]); | ||
153 | -// } | ||
154 | -// if ($params['prices']['max'] > 0) { | ||
155 | -// $queryCount->andWhere(['<=', 'pv.price', $params['prices']['max']]); | ||
156 | -// } | ||
157 | -// } | ||
158 | -// $query->addSelect(['_items_count' => $queryCount]); | ||
159 | - | ||
160 | - return $query; | ||
161 | - } | ||
162 | 107 | ||
163 | public function priceLimits($category = null, $params = []) { | 108 | public function priceLimits($category = null, $params = []) { |
164 | if (!empty($category)) { | 109 | if (!empty($category)) { |