예제 #1
0
 /**
  * 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;
 }