/** * 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; }
/** * 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(); $attribute = $filter->getAttributeModel(); $connection = $this->_getReadAdapter(); $tableAlias = $attribute->getAttributeCode() . '_idx'; $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId())); $collection->getSelect()->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array()); // MANA BEGIN: modify select formation to include multiple price ranges $condition = ''; foreach ($selections as $selection) { list($index, $range) = explode(',', $selection); $range = $this->getRange($index, $range); if ($condition != '') { $condition .= ' OR '; } $condition .= '((' . "{$tableAlias}.value" . ' >= ' . $range['from'] . ') ' . 'AND (' . "{$tableAlias}.value" . ($this->_isUpperBoundInclusive() ? ' <= ' : ' < ') . $range['to'] . '))'; } $collection->getSelect()->distinct()->where($condition); // MANA END return $this; }