Пример #1
0
 /**
  * Count products by attribute and option
  * @param ShopAttribute $attribute
  * @param string $option option id to search
  * @todo Optimize attributes merging
  * @return string
  */
 public function countAttributeProducts($attribute, $option)
 {
     if ($this->countAttr) {
         $model = new ShopProduct(null);
         $model->attachBehaviors($model->behaviors());
         $model->active()->cache($this->controller->cacheTime)->applyCategories($this->model)->applyMinPrice($this->convertCurrency(Yii::app()->request->getQuery('min_price')))->applyMaxPrice($this->convertCurrency(Yii::app()->request->getQuery('max_price')));
         if (Yii::app()->request->getParam('manufacturer')) {
             $model->applyManufacturers(explode(',', Yii::app()->request->getParam('manufacturer')));
         }
         $data = array($attribute->name => $option->id);
         $current = $this->getOwner()->activeAttributes;
         $newData = array();
         foreach ($current as $key => $row) {
             if (!isset($newData[$key])) {
                 $newData[$key] = array();
             }
             if (is_array($row)) {
                 foreach ($row as $v) {
                     $newData[$key][] = $v;
                 }
             } else {
                 $newData[$key][] = $row;
             }
         }
         $newData[$attribute->name][] = $option->id;
         return $model->withEavAttributes($newData)->count();
     }
 }