Example #1
0
 /**
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
  * @param Morphes_Filters_Model_Filter_Price $model
  * @param array $value
  * @return Morphes_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
 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 = floor($max * $this->getCurrencyRate());
     }
     return compact('min', 'max');
 }