/** * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection * @param Mana_Filters_Model_Filter_Price $model * @param array $value * @return Mana_Filters_Resource_Filter_Price */ public function applyToCollection($collection, $model, $value) { $collection->addPriceData($model->getCustomerGroupId(), $model->getWebsiteId()); $select = $collection->getSelect(); $response = $this->_dispatchPreparePriceEvent($model, $select); $table = $this->_getIndexTableAlias(); $additional = join('', $response->getAdditionalCalculations()); $fix = $this->_getConfigurablePriceFix(); $rate = $model->getCurrencyRate(); $precision = 2; //$filter->getDecimalDigits(); if ($this->isUpperBoundInclusive()) { $priceExpr = new Zend_Db_Expr("ROUND(({$table}.min_price {$additional} {$fix}) * {$rate}, {$precision})"); } else { $priceExpr = new Zend_Db_Expr("({$table}.min_price {$additional} {$fix}) * {$rate}"); } $condition = ''; foreach ($model->getMSelectedValues() as $selection) { if (strpos($selection, ',') !== false) { list($index, $range) = explode(',', $selection); $range = $this->getPriceRange($index, $range); if ($condition != '') { $condition .= ' OR '; } $condition .= '((' . $priceExpr . ' >= ' . $range['from'] . ') ' . 'AND (' . $priceExpr . ($this->isUpperBoundInclusive() ? ' <= ' : ' < ') . $range['to'] . '))'; } } if ($condition) { $select->distinct()->where("NOT ({$condition})"); } return $this; }
/** * Applies one or more price filters to currently viewed product collection * @param Mana_Filters_Model_Filter_Price $filter * @param array $selections * @return Mana_Filters_Resource_Filter_Price * This method is cloned from method applyFilterToCollection() in parent class (method body was pasted from parent class * and changed as needed. All changes marked with comments * Standard method did not give us possibility to filter multiple ranges. */ public function applyFilterToCollectionEx($filter, $selections) { $collection = $filter->getLayer()->getProductCollection(); $collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId()); $select = $collection->getSelect(); $response = $this->_dispatchPreparePriceEvent($filter, $select); $table = $this->_getIndexTableAlias(); $additional = join('', $response->getAdditionalCalculations()); $fix = $this->_getConfigurablePriceFix(); $rate = $filter->getCurrencyRate(); $precision = 2; //$filter->getDecimalDigits(); if ($this->_isUpperBoundInclusive()) { $priceExpr = new Zend_Db_Expr("ROUND(({$table}.min_price {$additional} {$fix}) * {$rate}, {$precision})"); } else { $priceExpr = new Zend_Db_Expr("({$table}.min_price {$additional} {$fix}) * {$rate}"); } // MANA BEGIN: modify select formation to include multiple price ranges $condition = ''; foreach ($selections as $selection) { list($index, $range) = explode(',', $selection); $range = $this->getPriceRange($index, $range); if ($condition != '') { $condition .= ' OR '; } $condition .= '((' . $priceExpr . ' >= ' . $range['from'] . ') ' . 'AND (' . $priceExpr . ($this->_isUpperBoundInclusive() ? ' <= ' : ' < ') . $range['to'] . '))'; } $select->distinct()->where($condition); // MANA END return $this; }