/**
  * @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;
 }
Example #2
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();
     $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;
 }
Example #3
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;
 }
Example #4
0
 public function getRangeOnCollection($collection)
 {
     $min = 0;
     $stats = $collection->getStats($this->_getFilterField());
     $max = $stats[$this->_getFilterField()]['max'];
     if (!is_numeric($max)) {
         return parent::getRangeOnCollection($collection);
     } else {
         $max = $this->_ceil($max * $this->getCurrencyRate());
     }
     return compact('min', 'max');
 }