/** * Apply price range filter to product collection * * @param Mage_Catalog_Model_Layer_Filter_Price $filter * @return Mage_Catalog_Model_Resource_Layer_Filter_Price */ public function applyPriceRange($filter) { $interval = $filter->getInterval(); if (!$interval) { return $this; } list($from, $to) = $interval; if ($from === '' && $to === '') { return $this; } $select = $filter->getLayer()->getProductCollection()->getSelect(); $priceExpr = $this->_getPriceExpression($filter, $select, false); if ($to !== '') { $to = (double) $to; if ($from == $to) { $to += self::MIN_POSSIBLE_PRICE; } } if ($from !== '') { $select->where($priceExpr . ' >= ' . $this->_getComparingValue($from, $filter)); } if ($to !== '') { $select->where($priceExpr . ' <= ' . $this->_getComparingValue($to, $filter)); } return $this; }
/** * Apply attribute filter to product collection * * @param Mage_Catalog_Model_Layer_Filter_Price $filter * @param int $range * @param int $index the range factor * * @return Celebros_Conversionpro_Model_Catalog_Layer_Filter_Decimal */ public function applyFilterToCollection($filter, $range, $index) { $productCollection = $filter->getLayer()->getProductCollection(); $attributeCode = $filter->getAttributeModel()->getAttributeCode(); $field = 'attr_decimal_' . $attributeCode; $value = array($field => array('from' => $range * ($index - 1), 'to' => $range * $index - 0.001)); $productCollection->addFqFilter($value); return $this; }
/** * Apply attribute filter to product collection * * @param Mage_Catalog_Model_Layer_Filter_Price $filter * @param int $range * @param int $index the range factor * @return Mage_Catalog_Model_Resource_Layer_Filter_Price */ public function applyFilterToCollection($filter, $range, $index) { $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()); $rate = $filter->getCurrencyRate(); $priceExpr = new Zend_Db_Expr("(({$table}.min_price {$additional}) * {$rate})"); $filters = $filter->getPriceRangeCustom(); if ($filters) { $select->where($priceExpr . ' >= ?', (int) $filters[0])->where($priceExpr . ' < ?', (int) $filters[1]); } else { $select->where($priceExpr . ' >= ?', $range * ($index - 1))->where($priceExpr . ' < ?', $range * $index); } return $this; }
/** * Retrieve minimal and maximal prices * * @param Mage_Catalog_Model_Layer_Filter_Price $filter * @return array (max, min) */ protected function _getMaxMinPrice($filter) { if (!$this->_maxMinPrice) { $select = clone $filter->getLayer()->getProductCollection()->getSelect(); $select->reset(Zend_Db_Select::LIMIT_OFFSET); $select->reset(Zend_Db_Select::COLUMNS); $select->reset(Zend_Db_Select::LIMIT_COUNT); $select->reset(Zend_Db_Select::ORDER); /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */ $collection = Mage::getResourceModel('catalog/product_collection'); $priceExpression = $collection->getPriceExpression($select) . ' ' . $collection->getAdditionalPriceExpression($select); $select = $this->_removePriceFromSelect($select, $priceExpression); $sqlEndPart = ') * ' . $collection->getCurrencyRate() . ')'; $select->columns('CEIL(MAX(' . $priceExpression . $sqlEndPart . ' as max_price'); $select->columns('FLOOR(MIN(' . $priceExpression . $sqlEndPart . ' as min_price'); $select->where($collection->getPriceExpression($select) . ' IS NOT NULL'); $this->_maxMinPrice = $collection->getConnection()->fetchRow($select, array(), Zend_Db::FETCH_NUM); } return $this->_maxMinPrice; }
/** * Apply price range filter to product collection * * @param Mage_Catalog_Model_Layer_Filter_Price $filter Filter * @return Mage_Catalog_Model_Resource_Layer_Filter_Price */ public function applyPriceRange($filter) { $intervals = $filter->getPriorIntervals(); if (!$intervals) { return $this; } $select = $filter->getLayer()->getProductCollection()->getSelect(); $priceExpr = $this->_getPriceExpression($filter, $select, false); $whereArray = array(); foreach ($intervals as $interval) { list($from, $to) = $interval; if ($from === '' && $to === '') { return $this; } if ($to !== '') { $to = (double) $to; if ($from == $to) { $to += self::MIN_POSSIBLE_PRICE; } } if ($from !== '' && $to !== '') { $whereArray[] = "({$priceExpr} >= {$this->_getComparingValue($from, $filter)} AND {$priceExpr} <= " . "{$this->_getComparingValue($to, $filter, false)})"; } else { if ($from !== '') { $whereArray[] = "({$priceExpr} >= {$this->_getComparingValue($from, $filter)})"; } if ($to !== '') { $whereArray[] = "({$priceExpr} <= {$this->_getComparingValue($to, $filter, false)})"; } } } $select->where(new Zend_db_Expr(implode(' OR ', $whereArray))); return $this; }
/** * Apply attribute filter to product collection * * @param Mage_Catalog_Model_Layer_Filter_Price $filter * @param int $range * @param int $index the range factor * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Attribute */ public function applyFilterToCollection($filter, $value) { $collection = $filter->getLayer()->getProductCollection(); //$collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId()); $select = $collection->getSelect(); $this->prepareSelect($filter, $value, $select); $attribute_code = 'price'; $base_select = $filter->getLayer()->getBaseSelect(); foreach ($base_select as $code => $select) { if ($attribute_code != $code) { $this->prepareSelect($filter, $value, $select); } } return $this; }
/** * Prepare filter apply * * @param Mage_Catalog_Model_Layer_Filter_Price $filter * @return array */ protected function _prepareApply($filter) { $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()); $rate = $filter->getCurrencyRate(); $priceExpr = new Zend_Db_Expr("(({$table}.min_price {$additional}) * {$rate})"); return array($select, $priceExpr); }