Commit 9d539ac3212432464422ad8194c3b2fc2ce28cee
1 parent
433709ce
Brands and options count
Showing
6 changed files
with
28 additions
and
9 deletions
Show diff stats
common/modules/product/CatalogUrlManager.php
| ... | ... | @@ -118,6 +118,12 @@ class CatalogUrlManager implements UrlRuleInterface { |
| 118 | 118 | |
| 119 | 119 | $this->setFilterUrl($params, $url); |
| 120 | 120 | |
| 121 | + foreach ($params as $key => $param) { | |
| 122 | + if (empty($params[$key])) { | |
| 123 | + unset($params[$key]); | |
| 124 | + } | |
| 125 | + } | |
| 126 | + | |
| 121 | 127 | if (!empty($params) && ($query = http_build_query($params)) !== '') { |
| 122 | 128 | $url .= '?' . $query; |
| 123 | 129 | } |
| ... | ... | @@ -193,7 +199,9 @@ class CatalogUrlManager implements UrlRuleInterface { |
| 193 | 199 | break; |
| 194 | 200 | } |
| 195 | 201 | } |
| 196 | - $url .= 'filter:'. implode(';', $filter); | |
| 202 | + if (!empty($filter)) { | |
| 203 | + $url .= 'filter:'. implode(';', $filter); | |
| 204 | + } | |
| 197 | 205 | unset($params['filter']); |
| 198 | 206 | } |
| 199 | 207 | } | ... | ... |
common/modules/product/models/Brand.php
common/modules/product/models/BrandSearch.php
| ... | ... | @@ -97,8 +97,11 @@ class BrandSearch extends Brand |
| 97 | 97 | ->innerJoin(Product::tableName(), Product::tableName() .'.brand_id='. Brand::tableName() .'.brand_id') |
| 98 | 98 | ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.product_id='. Product::tableName() .'.product_id') |
| 99 | 99 | ->with(['brandName']); |
| 100 | + $query->innerJoin('product_variant', 'product_variant.product_id = '. Product::tableName() .'.product_id'); | |
| 101 | + $query->where(['!=', 'product_variant.stock', 0]); | |
| 102 | + $query->groupBy(Product::tableName() .'.product_id'); | |
| 100 | 103 | if (!empty($category)) { |
| 101 | - $query->where([ | |
| 104 | + $query->andWhere([ | |
| 102 | 105 | ProductCategory::tableName() .'.category_id' => $category->category_id |
| 103 | 106 | ]); |
| 104 | 107 | } | ... | ... |
frontend/controllers/CatalogController.php
| ... | ... | @@ -145,6 +145,7 @@ class CatalogController extends \yii\web\Controller |
| 145 | 145 | 'brandModel' => $brandModel, |
| 146 | 146 | 'brands' => $brands, |
| 147 | 147 | 'filter' => $filter, |
| 148 | + 'params' => $params, | |
| 148 | 149 | 'productModel' => $productModel, |
| 149 | 150 | 'productProvider' => $productProvider, |
| 150 | 151 | 'groups' => $groups, | ... | ... |
frontend/models/ProductFrontendSearch.php
| ... | ... | @@ -94,20 +94,25 @@ class ProductFrontendSearch extends Product { |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | public function optionsForCategory($category = null, $params = []) { |
| 97 | -// , | |
| 98 | -// 'COUNT('. ProductOption::tableName() .'.product_id) AS _items_count' | |
| 99 | 97 | $query = TaxOption::find() |
| 100 | 98 | ->select([ |
| 101 | - TaxOption::tableName() .'.*' | |
| 99 | + TaxOption::tableName() .'.*', | |
| 100 | + 'COUNT('. ProductOption::tableName() .'.product_id) AS _items_count' | |
| 102 | 101 | ]) |
| 103 | 102 | ->innerJoin(ProductOption::tableName(), ProductOption::tableName() .'.option_id='. TaxOption::tableName() .'.tax_option_id') |
| 104 | 103 | ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.product_id='. ProductOption::tableName() .'.product_id') |
| 105 | 104 | ->innerJoin(TaxGroup::tableName(), TaxGroup::tableName() .'.tax_group_id='. TaxOption::tableName() .'.tax_group_id') |
| 106 | - ->andWhere([TaxGroup::tableName() .'.is_filter' => true]); | |
| 105 | + ->where([TaxGroup::tableName() .'.is_filter' => true]); | |
| 106 | + | |
| 107 | + $query->leftJoin('product_variant', 'product_variant.product_id = '. ProductCategory::tableName() .'.product_id'); | |
| 108 | + $query->andWhere(['!=', 'product_variant.stock', 0]); | |
| 109 | + $query->groupBy(TaxOption::tableName() .'.tax_option_id'); | |
| 110 | +// $query->having(['>', 'COUNT(product_variant.product_variant_id)', 0]); | |
| 111 | + | |
| 107 | 112 | if (!empty($category)) { |
| 108 | 113 | $query->andWhere([ProductCategory::tableName() .'.category_id' => $category->category_id]); |
| 109 | 114 | } |
| 110 | - $query->groupBy(TaxOption::tableName() .'.tax_option_id'); | |
| 115 | + | |
| 111 | 116 | $query->orderBy(TaxOption::tableName() .'.sort', SORT_ASC); |
| 112 | 117 | $query->limit(null); |
| 113 | 118 | if (!empty($params['prices'])) { | ... | ... |
frontend/views/catalog/products.php
| ... | ... | @@ -120,7 +120,7 @@ $this->registerJsFile(Yii::getAlias('@web/js/ion.rangeSlider.js'),[ |
| 120 | 120 | ?> |
| 121 | 121 | <li> |
| 122 | 122 | <input type="checkbox" class="brands-option" <?= $checked ? ' checked' : ''?> onchange="document.location='<?= $option_url?>'" /> |
| 123 | - <a href="<?= $option_url?>"><?= $brand->name?><?php /* (<?= $brand->getProducts()->count()?>)*/?></a> | |
| 123 | + <a href="<?= $option_url?>"><?= $brand->name?> (<?= $brand->_items_count?>)</a> | |
| 124 | 124 | </li> |
| 125 | 125 | <?php endforeach?> |
| 126 | 126 | </ul> |
| ... | ... | @@ -138,7 +138,7 @@ $this->registerJsFile(Yii::getAlias('@web/js/ion.rangeSlider.js'),[ |
| 138 | 138 | ?> |
| 139 | 139 | <li> |
| 140 | 140 | <input type="checkbox" class="features-option" onchange="document.location='<?= $option_url?>'" <?php /* name="option[<?= $group->alias?>][]"value="<?= $option->alias?>"*/?><?= $checked ? ' checked' : ''?> /> |
| 141 | - <a href="<?= $option_url?>"><?= $option->ValueRenderHTML?><?php /* (<?= $option->_items_count?>)*/?></a> | |
| 141 | + <a href="<?= $option_url?>"><?= $option->ValueRenderHTML?> (<?= $option->_items_count?>)</a> | |
| 142 | 142 | </li> |
| 143 | 143 | <?php endforeach?> |
| 144 | 144 | </ul> | ... | ... |