/** * 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; }
protected function setUp() { $this->_model = new Mage_Catalog_Model_Layer_Filter_Price_Algorithm(); $this->_layer = new Mage_Catalog_Model_Layer(); $this->_filter = new Mage_Catalog_Model_Layer_Filter_Price(); $this->_filter->setLayer($this->_layer)->setAttributeModel(new Varien_Object(array('attribute_code' => 'price'))); }
/** * 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; }
/** * Get data for build price filter items * * @return array */ protected function _getItemsData() { if (!Mage::getStoreConfig('amshopby/general/use_custom_ranges')) { return parent::_getItemsData(); } $key = $this->_getCacheKey(); $data = $this->getLayer()->getAggregator()->getCacheData($key); if ($data === null) { $ranges = $this->_getCustomRanges(); $counts = $this->_getResource()->getFromToCount($this, $ranges); $data = array(); foreach ($counts as $index => $count) { if (!$index) { // index may be NULL if some products has price out of all ranges continue; } $from = $ranges[$index][0]; $to = $ranges[$index][1]; $data[] = array('label' => $this->_renderFromToItemLabel($from, $to), 'value' => $from . '-' . $to, 'count' => $count, 'pos' => $from); } usort($data, array($this, '_srt')); $tags = array(Mage_Catalog_Model_Product_Type_Price::CACHE_TAG); $tags = $this->getLayer()->getStateTags($tags); $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags); } return $data; }
public function testGetSetCurrencyRate() { $this->assertEquals(1, $this->_model->getCurrencyRate()); $currencyRate = 42; $this->_model->setCurrencyRate($currencyRate); $this->assertEquals($currencyRate, $this->_model->getCurrencyRate()); }
/** * Apply price range filter to collection * * @param Zend_Controller_Request_Abstract $request * @param $filterBlock * * @return Mage_Catalog_Model_Layer_Filter_Price */ public function apply(Zend_Controller_Request_Abstract $request, $filterBlock) { if (Mage::helper('mtfilter')->isPriceEnable() && version_compare(Mage::getVersion(), '1.7.0.0') < 0) { /** * Filter must be string: $index,$range */ $filter = $request->getParam($this->getRequestVar()); if (!$filter) { return $this; } $filter = explode('-', $filter); if (count($filter) != 2) { return $this; } list($index, $range) = $filter; if (is_numeric($index) && is_numeric($range)) { $this->setPriceRange((int) $range); $this->setPriceRangeCustom($filter); $this->_applyToCollection($range, $index); $this->getLayer()->getState()->addFilter($this->_createItem($this->_renderItemLabelCustom($index, $range), $filter)); $this->_items = array(); } return $this; } else { parent::apply($request, $filterBlock); } }
/** * Prepare response object and dispatch prepare price event * * Return response object * * @param Mage_Catalog_Model_Layer_Filter_Price $filter * @param Varien_Db_Select $select * @return Varien_Object */ protected function _dispatchPreparePriceEvent($filter, $select) { // prepare response object for event $response = new Varien_Object(); $response->setAdditionalCalculations(array()); // prepare event arguments $eventArgs = array('select' => $select, 'table' => $this->_getIndexTableAlias(), 'store_id' => $filter->getStoreId(), 'response_object' => $response); /** * @deprecated since 1.3.2.2 */ Mage::dispatchEvent('catalogindex_prepare_price_select', $eventArgs); /** * @since 1.4 */ Mage::dispatchEvent('catalog_prepare_price_select', $eventArgs); return $response; }
/** * Prepare price filter model * * @param Magento_Test_Request|null $request * @return void */ protected function _prepareFilter($request = null) { $layer = new Mage_Catalog_Model_Layer(); $layer->setCurrentCategory(4); $layer->setState(new Mage_Catalog_Model_Layer_State()); $filter = new Mage_Catalog_Model_Layer_Filter_Price(); $filter->setLayer($layer)->setAttributeModel(new Varien_Object(array('attribute_code' => 'price'))); if (!is_null($request)) { $filter->apply($request, new Mage_Core_Block_Text()); $interval = $filter->getInterval(); if ($interval) { $this->_model->setLimits($interval[0], $interval[1]); } } $collection = $layer->getProductCollection(); $this->_model->setPricesModel($filter)->setStatistics($collection->getMinPrice(), $collection->getMaxPrice(), $collection->getPriceStandardDeviation(), $collection->getSize()); }
/** * Get price range for building filter steps * * @return int */ public function getPriceRange() { if ($range = intval(Mage::helper('ecommerceteam_sln')->getConfigData('pricerange'))) { if ($range > 0) { return $range; } } return parent::getPriceRange(); }
/** * 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; }
protected function _renderRangeLabel($fromPrice, $toPrice) { //if (method_exists(get_parent_class($this), "_renderRangeLabel")) { // return parent::_renderRangeLabel($fromPrice, $toPrice); // } else { $range = $toPrice - $fromPrice; $value = $toPrice / $range; return parent::_renderItemLabel($range, $value); //} }
/** * 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; }
public function apply(Zend_Controller_Request_Abstract $request, $filterBlock) { return parent::apply($request, $filterBlock); // $filter = $request->getParam($this->getRequestVar()); // if (!$filter) return $this; // // $layeredNavigationCanonical = $this->getAttributeModel()->getLayeredNavigationCanonical(); // if ($layeredNavigationCanonical==1) { // $layerCanonicalFilter = Mage::registry('layer_canonical_filter'); // if (!$layerCanonicalFilter) $layerCanonicalFilter = array(); // $attributeCode = $this->getAttributeModel()->getAttributeCode(); // $layerCanonicalFilter[$attributeCode] = $filter; //$layeredNavigationCanonical; // Mage::unregister('layer_canonical_filter'); // Mage::register('layer_canonical_filter', $layerCanonicalFilter); // } }
/** * Retrieves max price for ranges definition. * * @return float */ public function getMaxPriceInt() { $searchParams = $this->getLayer()->getProductCollection()->getExtendedSearchParams(); $uniquePart = strtoupper(md5(serialize($searchParams))); $cacheKey = 'MAXPRICE_' . $this->getLayer()->getStateKey() . '_' . $uniquePart; $cachedData = Mage::app()->loadCache($cacheKey); if (!$cachedData) { $stats = $this->getLayer()->getProductCollection()->getStats($this->_getFilterField()); $max = $this->_isFacetMaxPriceSet($stats) ? $stats['facets'][$this->_getFilterField()]['max'] : null; if (!is_numeric($max)) { $max = parent::getMaxPriceInt(); } $cachedData = (double) $max; $tags = $this->getLayer()->getStateTags(); $tags[] = self::CACHE_TAG; Mage::app()->saveCache($cachedData, $cacheKey, $tags); } return $cachedData; }
/** * Get price range for building filter steps * * @return int */ public function getPriceRange() { if (!Mage::helper('searchanise/ApiSe')->checkSearchaniseResult(true)) { return parent::getPriceRange(); } $collection = $this->getLayer()->getProductCollection(); if (!method_exists($collection, 'checkSearchaniseResult') || !$collection->checkSearchaniseResult()) { return parent::getPriceRange(); } $newRange = $collection->getSearchaniseRequest()->getPriceRangeFromAttribute($this->getAttributeModel()); if (!$newRange) { return parent::getPriceRange(); } $rate = Mage::app()->getStore()->getCurrentCurrencyRate(); if (!$rate || $rate == 1) { // nothing } else { $newRange *= $rate; } return $newRange; }
/** * Apply price range filter * * @param Zend_Controller_Request_Abstract $request * @param $filterBlock * * @return Mage_Catalog_Model_Layer_Filter_Price */ public function apply(Zend_Controller_Request_Abstract $request, $filterBlock) { if (!Mage::helper('catalogfilter')->priceIsSlider()) { return parent::apply($request, $filterBlock); } /** * Filter must be string: $fromPrice-$toPrice */ $filter = $request->getParam($this->getRequestVar()); if (!$filter) { return $this; } //validate filter $filterParams = explode(',', $filter); $filter = $this->_validateFilter($filterParams[0]); if (!$filter) { return $this; } list($from, $to) = $filter; $this->setInterval(array($from, $to)); $priorFilters = array(); for ($i = 1; $i < count($filterParams); ++$i) { $priorFilter = $this->_validateFilter($filterParams[$i]); if ($priorFilter) { $priorFilters[] = $priorFilter; } else { //not valid data $priorFilters = array(); break; } } if ($priorFilters) { $this->setPriorIntervals($priorFilters); } $this->_applyPriceRange(); Mage::getSingleton('catalogfilter/layer_state')->addFilter($this->getRequestVar(), $filter); return $this; }
/** * Get maximum price from layer products set using cache * * @return float */ public function getMaxPriceInt() { $searchParams = $this->getLayer()->getProductCollection()->getExtendedSearchParams(); $spSerialized = serialize($searchParams); $uniquePart = strtoupper(md5(serialize($spSerialized . '_' . $this->getCurrencyRate()))); $cacheKey = 'MAXPRICE_' . $this->getLayer()->getStateKey() . '_' . $uniquePart; $cachedData = Mage::app()->loadCache($cacheKey); if (!$cachedData) { $stats = $this->getLayer()->getProductCollection()->getStats($this->_getFilterField()); $max = $stats[$this->_getFilterField()]['max']; if (!is_numeric($max)) { $max = parent::getMaxPriceInt(); } else { $max = floor($max * $this->getCurrencyRate()); } $cachedData = $max; $tags = $this->getLayer()->getStateTags(); $tags[] = self::CACHE_TAG; Mage::app()->saveCache($cachedData, $cacheKey, $tags); } return $cachedData; }
/** * Retrieves max price for ranges definition. * * @return float */ public function getMaxPriceInt() { $stats = $this->_getFieldStats(); $max = $stats['max']; if (!is_numeric($max)) { $max = parent::getMaxPriceInt(); } return $max; }
/** * Get maximum price from layer products set using cache * * @return float */ public function getMaxPriceInt() { $searchParams = $this->getLayer()->getProductCollection()->getExtendedSearchParams(); $uniquePart = strtoupper(md5(serialize($searchParams . '_' . $this->getCurrencyRate()))); $cacheKey = 'MAXPRICE_' . $this->getLayer()->getStateKey() . '_' . $uniquePart; $cachedData = Mage::app()->loadCache($cacheKey); if (!$cachedData) { $stats = $this->getLayer()->getProductCollection()->getStats($this->_getFilterField()); //This replaces the search I commented out below, and gets the right max price from the db. $max = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id', array('in' => $stats['ids']))->addAttributeToSelect('price')->addAttributeToSort('price', 'desc')->getFirstItem()->getPrice(); //$max = $stats[$this->_getFilterField()]['max']; if (!is_numeric($max)) { $max = parent::getMaxPriceInt(); } else { $max = floor($max * $this->getCurrencyRate()); } $cachedData = $max; $tags = $this->getLayer()->getStateTags(); $tags[] = self::CACHE_TAG; Mage::app()->saveCache($cachedData, $cacheKey, $tags); } return $cachedData; }
protected function _applyPriceRange() { if (version_compare(Mage::getVersion(), '1.12.0.0', '>=')) { if (Mage::helper('adjnav')->isSolrEnabled()) { list($from, $to) = $this->getInterval(); $this->getLayer()->getProductCollection()->addFqFilter(array($this->_getFilterField() => $this->_prepareFacetRange($from, $to))); return $this; } else { return parent::_applyPriceRange(); } } }
/** * 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; } list($select, $priceExpr) = $this->_prepareApply($filter); if ($from == $to && !empty($to)) { $select->where($priceExpr . ' = ?', $from); } else { if ($from !== '') { $select->where($priceExpr . ' >= ?', $from); } if ($to !== '') { $select->where($priceExpr . ' < ?', $to); } } 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; }
public function apply(Zend_Controller_Request_Abstract $request, $filterBlock) { $version = Mage::getVersionInfo(); if (!$this->usePriceRanges() || (int) $version['minor'] >= 7) { return parent::apply($request, $filterBlock); } else { /** * Filter must be string: $fromPrice-$toPrice */ $filter = $request->getParam($this->getRequestVar()); if (!$filter) { return $this; } $filter = explode('-', $filter); if (count($filter) != 2) { return $this; } foreach ($filter as $v) { if ($v !== '' && $v !== '0' && (int) $v <= 0 || is_infinite((int) $v)) { return $this; } } list($from, $to) = $filter; $this->setInterval(array($from, $to)); $this->_applyToCollection($from, $to); $this->getLayer()->getState()->addFilter($this->_createItem($this->_renderRangeLabel(empty($from) ? 0 : $from, $to), $filter)); $this->_items = array(); return $this; } }
/** * Find price separator for the quantile * * @param int $quantileNumber should be from 1 to n-1 where n is number of intervals * @return array|null */ protected function _findPriceSeparator($quantileNumber) { if ($quantileNumber < 1 || $quantileNumber >= $this->getIntervalsNumber()) { return null; } $prices = array(); $quantileInterval = $this->_getQuantileInterval($quantileNumber); $intervalPricesCount = $quantileInterval[1] - $quantileInterval[0] + 1; $offset = $quantileInterval[0]; if (!is_null($this->_lastPriceLimiter[0])) { $offset -= $this->_lastPriceLimiter[0]; } if ($offset < 0) { $intervalPricesCount += $offset; $prices = array_slice($this->_prices, $this->_lastPriceLimiter[0] + $offset - $this->_quantileInterval[0], -$offset); $offset = 0; } $lowerPrice = $this->_lastPriceLimiter[1]; if (!is_null($this->_lowerLimit)) { $lowerPrice = max($lowerPrice, $this->_lowerLimit); } if ($intervalPricesCount >= 0) { $prices = array_merge($prices, $this->_pricesModel->loadPrices($intervalPricesCount + 1, $offset, $lowerPrice, $this->_upperLimit)); } $lastPrice = $prices[$intervalPricesCount - 1]; $bestRoundPrice = array(); if ($lastPrice == $prices[0]) { if ($quantileNumber == 1 && $offset) { $additionalPrices = $this->_pricesModel->loadPreviousPrices($lastPrice, $quantileInterval[0], $this->_lowerLimit); if ($additionalPrices) { $quantileInterval[0] -= count($additionalPrices); $prices = array_merge($additionalPrices, $prices); $bestRoundPrice = $this->_findRoundPrice($prices[0] + Mage_Catalog_Model_Resource_Layer_Filter_Price::MIN_POSSIBLE_PRICE / 10, $lastPrice, false); } } if ($quantileNumber == $this->getIntervalsNumber() - 1) { $pricesCount = count($prices); if ($prices[$pricesCount - 1] > $lastPrice) { $additionalPrices = array($prices[$pricesCount - 1]); } else { $additionalPrices = $this->_pricesModel->loadNextPrices($lastPrice, $this->_count - $quantileInterval[0] - count($prices), $this->_upperLimit); } if ($additionalPrices) { $quantileInterval[1] = $quantileInterval[0] + count($prices) - 1; if ($prices[$pricesCount - 1] <= $lastPrice) { $quantileInterval[1] += count($additionalPrices); $prices = array_merge($prices, $additionalPrices); } $upperBestRoundPrice = $this->_findRoundPrice($lastPrice + Mage_Catalog_Model_Resource_Layer_Filter_Price::MIN_POSSIBLE_PRICE / 10, $prices[count($prices) - 1], false); $this->_mergeRoundPrices($bestRoundPrice, $upperBestRoundPrice); } } } else { $bestRoundPrice = $this->_findRoundPrice($prices[0] + Mage_Catalog_Model_Resource_Layer_Filter_Price::MIN_POSSIBLE_PRICE / 10, $lastPrice); } $this->_quantileInterval = $quantileInterval; $this->_prices = $prices; if (empty($bestRoundPrice)) { $this->_skippedQuantilesUpperLimits[$quantileNumber] = $quantileInterval[1]; return $bestRoundPrice; } $pricesCount = count($prices); if ($prices[$pricesCount - 1] > $lastPrice) { $this->_lastPriceLimiter = array($quantileInterval[0] + $pricesCount - 1, $prices[$pricesCount - 1]); } ksort($bestRoundPrice, SORT_NUMERIC); foreach ($bestRoundPrice as $index => &$bestRoundPriceValues) { if (empty($bestRoundPriceValues)) { unset($bestRoundPrice[$index]); } else { sort($bestRoundPriceValues); } } return array_reverse($bestRoundPrice); }
/** * Apply decimal range filter to product collection * * @param Zend_Controller_Request_Abstract $request * @param Mage_Catalog_Block_Layer_Filter_Decimal $filterBlock * @return Mage_Catalog_Model_Layer_Filter_Decimal */ public function _______apply(Zend_Controller_Request_Abstract $request, $filterBlock) { parent::apply($request, $filterBlock); /** * Filter must be string: $index, $range */ $filter = $request->getParam($this->getRequestVar()); if (!$filter) { return $this; } $filter = explode(',', $filter); if (count($filter) != 2) { return $this; } list($index, $range) = $filter; if ((int) $index && (int) $range) { $this->setRange((int) $range); $this->_getResource()->applyFilterToCollection($this, $range, $index); $this->getLayer()->getState()->addFilter($this->_createItem($this->_renderItemLabel($range, $index), $filter)); $this->_items = array(); } return $this; }
/** * For 1.3 ONLY. I LOVE 1.3 :) */ public function getRangeItemCounts($range) { if (!Mage::helper('amshopby')->isVersionLessThan(1, 4)) { return parent::getRangeItemCounts($range); } $items = $this->getData('range_item_counts_' . $range); if (is_null($items)) { // logic is the same, but we need to pass different params. $items = $this->_getResource()->getCount($this->getAttributeModel(), $range, $this->_getBaseCollectionSql()); $this->setData('range_item_counts_' . $range, $items); } return $items; }
/** * Get maximum price from layer products set using cache * * @return float */ public function getMaxPriceInt() { $cacheKey = $this->_getUniqueCacheKey('MAXPRICE'); $cachedData = Mage::app()->loadCache($cacheKey); if (!$cachedData) { $stats = $this->getLayer()->getProductCollection()->getStats($this->_getFilterField()); $max = $stats[$this->_getFilterField()]['max']; if (!is_numeric($max)) { $max = parent::getMaxPriceInt(); } else { $max = floor($max * $this->getCurrencyRate()); } $cachedData = $max; $tags = $this->getLayer()->getStateTags(); $tags[] = self::CACHE_TAG; Mage::app()->saveCache($cachedData, $cacheKey, $tags); } return $cachedData; }
/** * For 1.3 ONLY. I LOVE 1.3 :) */ public function getRangeItemCounts($range) { //slider if (3 == Mage::getStoreConfig('amshopby/general/price_type')) { return array(0 => 1, 1 => 2); } if (!Mage::helper('amshopby')->isVersionLessThan(1, 4)) { return parent::getRangeItemCounts($range); } $items = $this->getData('range_item_counts_' . $range); if (is_null($items)) { $items = $this->_getResource()->getCount($this->getAttributeModel(), $range, $this->_getBaseCollectionSql()); $this->setData('range_item_counts_' . $range, $items); } return $items; }
/** * 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; }
/** * Retrieve array with products counts per price range * * @param Mage_Catalog_Model_Layer_Filter_Price $filter * @param int $range * @return array */ public function getCountAttributePrice($filter, $range) { $ret = array(); $rate = $this->getCurrentCurrencyRate($this->store); if (empty($filter) || empty($rate)) { return $ret; } $attribute = $filter->getAttributeModel(); if (empty($attribute)) { return $ret; } // hook, it is need for 'union' and this attribute defined in the 'price' field if ($attribute->getAttributeCode() == 'price') { $label = 'price'; } else { $label = 'attribute_' . $attribute->getId(); } if (!$this->checkAttributesCountLabel($label)) { $vals = array(); $res = $this->getSearchResult(); if (!empty($res['facets'])) { foreach ($res['facets'] as $facet) { if ($facet['attribute'] == $label) { if (!empty($facet['buckets'])) { foreach ($facet['buckets'] as $bucket) { // Example //~ [value] => 1000-2000 //~ [title] => 1000 - 2000 //~ [from] => 1000 //~ [to] => 2000 //~ [count] => 2 $numberStep = round($bucket['to'] * $rate / $range); if ($numberStep > 0) { $vals[$numberStep] = $bucket['count']; } } } } } } $this->setAttributesCountLabel($vals, $label); } return $this->getAttributesCountLabel($label); }