Commit a18604168028018a1430ddf4f7e014c6480d5261

Authored by Karnovsky A
1 parent c91d116e

Items count for options

common/modules/rubrication/models/TaxOption.php
@@ -34,6 +34,7 @@ use yii\db\ActiveRecord; @@ -34,6 +34,7 @@ use yii\db\ActiveRecord;
34 */ 34 */
35 class TaxOption extends \yii\db\ActiveRecord 35 class TaxOption extends \yii\db\ActiveRecord
36 { 36 {
  37 + public $_items_count;
37 /** 38 /**
38 * @inheritdoc 39 * @inheritdoc
39 */ 40 */
frontend/controllers/CatalogController.php
@@ -74,6 +74,10 @@ class CatalogController extends \yii\web\Controller @@ -74,6 +74,10 @@ class CatalogController extends \yii\web\Controller
74 $brands_count = $brandsQuery->count(); 74 $brands_count = $brandsQuery->count();
75 75
76 $optionsQuery = TaxOption::find() 76 $optionsQuery = TaxOption::find()
  77 + ->select([
  78 + TaxOption::tableName() .'.*',
  79 + 'COUNT('. ProductOption::tableName() .'.product_id) AS _items_count'
  80 + ])
77 ->innerJoin(ProductOption::tableName(), ProductOption::tableName() .'.option_id='. TaxOption::tableName() .'.tax_option_id') 81 ->innerJoin(ProductOption::tableName(), ProductOption::tableName() .'.option_id='. TaxOption::tableName() .'.tax_option_id')
78 ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.product_id='. ProductOption::tableName() .'.product_id') 82 ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.product_id='. ProductOption::tableName() .'.product_id')
79 ->where([ 83 ->where([
frontend/views/catalog/products.php
@@ -77,7 +77,7 @@ $this->params['breadcrumbs'][] = $category->name; @@ -77,7 +77,7 @@ $this->params['breadcrumbs'][] = $category->name;
77 <?php foreach($group->_options as $option) :?> 77 <?php foreach($group->_options as $option) :?>
78 <div class="checkbox"> 78 <div class="checkbox">
79 <label><input type="checkbox" name="option[<?= $group->alias?>][]" value="<?= $option->alias?>"<?= (isset($options[$group->alias]) && in_array($option->alias, $options[$group->alias])) ? ' checked' : ''?> /></label> 79 <label><input type="checkbox" name="option[<?= $group->alias?>][]" value="<?= $option->alias?>"<?= (isset($options[$group->alias]) && in_array($option->alias, $options[$group->alias])) ? ' checked' : ''?> /></label>
80 - <a href="#"><?= $option->ValueRenderHTML?></a> 80 + <a href="#"><?= $option->ValueRenderHTML?>&nbsp;(<?= $option->_items_count?>)</a>
81 </div> 81 </div>
82 <?php endforeach?> 82 <?php endforeach?>
83 </div> 83 </div>