public function getParamsMaxBounds($refresh = false) { if ($this->_paramsMaxBounds == null || $refresh) { $bounds = array(); $model = new Product(); $criteria = $this->_getSearchCriteria(true); //$model->attachEavSet(1); /* $criteria = $this->_searchCriteria !== null ? $this->_searchCriteria : new CDbCriteria(); * */ $criteria->select = 't.id'; $a = $model->findAll($criteria); var_dump($a); $productsIds = CHtml::listData($a, 'id', 'id'); foreach ($this->getEavAttributesList() as $name => $attr) { if ($attr->data_type == EavAttribute::DATA_TYPE_NUMERIC) { $c = new CDbCriteria(); $c->select = 'MAX(`value`) as `maxValue`'; if (is_array($productsIds) && !empty($productsIds)) { $c->addInCondition('entity_id', $productsIds); } $c->addCondition('eav_attribute_id = :eav_attribute_id'); $c->params[':eav_attribute_id'] = $attr->id; $max = NumericDataType::model()->find($c); $bounds[$name] = $max->maxValue; } } $this->_paramsMaxBounds = $bounds; } return $this->_paramsMaxBounds; }
public function getParamsCurrentBounds($refresh = false) { if ($this->_paramsCurrentBounds == null || $refresh) { $oldBounds = $this->_paramsCurrentBounds; $bounds = array(); $model = new Product(); $criteria = $this->_searchCriteria !== null ? $this->_getSearchCriteria(true) : new CDbCriteria(); $criteria->select = 't.id'; $productsIds = CHtml::listData(Product::model()->findAll($criteria), 'id', 'id'); foreach ($this->getEavAttributesList() as $name => $attr) { if ($attr->data_type == EavAttribute::DATA_TYPE_NUMERIC) { $c = new CDbCriteria(); $c->select = 'MAX(`value`) as `maxValue`'; if (is_array($productsIds) && !empty($productsIds)) { $c->addInCondition('entity_id', $productsIds); } $c->addCondition('eav_attribute_id = :eav_attribute_id'); $c->params[':eav_attribute_id'] = $attr->id; $max = NumericDataType::model()->find($c); $bounds[$name] = (int) $max->maxValue > 0 ? $max->maxValue : $oldBounds[$attr->name]; } } $this->_paramsCurrentBounds = $bounds; } $this->_refreshRanges(); return $this->_paramsCurrentBounds; }
public function getParamsMaxBounds() { if ($this->_paramsMaxBounds == null) { $bounds = array(); // Цена $max = self::model()->find(array('select' => 'MAX(`price_eur`) as price_eur', 'condition' => 't.category_id = :category_id', 'params' => array(':category_id' => $this->category_id))); $bounds['price'] = (double) $max['price_eur'] > 0 ? 1000 * (1 + floor($max['price_eur'] * $this->_getEuroRate() / 1000)) : self::MAX_BOUNDS_VALUE; // Динамические атрибуты foreach ($this->getEavAttributesList() as $name => $attr) { if ($attr->data_type != EavAttribute::DATA_TYPE_NUMERIC) { continue; } $max = Yii::app()->db->createCommand()->select('MAX(`value`) as `maxValue`')->from(NumericDataType::model()->tableName() . ' t')->join($this->tableName() . ' p', 't.entity_id = p.id')->where('t.eav_attribute_id = :eav_attribute_id AND t.entity = :entity AND p.category_id = :category_id AND p.status = :status', array(':eav_attribute_id' => $attr->id, ':entity' => get_class($this), ':category_id' => $this->category_id, ':status' => self::STATUS_PUBLISHED))->queryRow(); $bounds[$name] = (int) $max['maxValue'] > 0 ? $max['maxValue'] : self::MAX_BOUNDS_VALUE; } $this->_paramsMaxBounds = $this->_paramsCurrentBounds = $bounds; } return $this->_paramsMaxBounds; }