Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 3
How do I Change price filter to split by 100’s rather then 1000’s? 
 
ghurty
Member
 
Total Posts:  31
Joined:  2009-08-30
 

In the filter by column, the price is being broken into two groups (0 - 1000 and 1000 - 2000) How can I set it that it splits it up by 100’s?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
liangrongze
Jr. Member
 
Total Posts:  11
Joined:  2009-06-08
 

It can’t be modify like what you say..... you must modify the resouce code ...I tried bofore.

 
Magento Community Magento Community
Magento Community
Magento Community
 
NELAGeek
Sr. Member
 
Avatar
Total Posts:  193
Joined:  2010-01-23
US
 

Here’s my fix.  Hopefully they’ll change this in an upcoming version or something.

Change the code in /app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php from:

public function getPriceRange()
    
{
        $range 
$this->getData('price_range');
        if (
is_null($range)) {
            $maxPrice 
$this->getMaxPriceInt();
        
$index 1;
            do 
{
                $range 
pow(10, (strlen(floor($maxPrice))-$index));
                
$items $this->getRangeItemCounts($range);
                
$index++;
            
}
            
while($range>self::MIN_RANGE_POWER && count($items)<2);

            
$this->setData('price_range'$range);
        
}
        
return $range;
    
}

to this:

public function getPriceRange()
    
{
        $range 
$this->getData('price_range');
        if (
is_null($range)) {
            $maxPrice 
$this->getMaxPriceInt();
        
$index 2;
            if (
$maxPrice<1000{
        $index 
1;
        
}
            
do {
                $range 
pow(10, (strlen(floor($maxPrice))-$index));
                
$items $this->getRangeItemCounts($range);
                
$index++;
            
}
            
while($range>self::MIN_RANGE_POWER && count($items)<2);

            
$this->setData('price_range'$range);
        
}
        
return $range;
    
}

Hope this works for ya.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mott
Member
 
Total Posts:  47
Joined:  2008-04-13
Los Angeles, CA
 

This did not work for me.

 
Magento Community Magento Community
Magento Community
Magento Community
 
NELAGeek
Sr. Member
 
Avatar
Total Posts:  193
Joined:  2010-01-23
US
 

did you refresh cache?  did it have any effect?  What ver of Magento are you running?  I haven’t tried this yet on ver 1.4.01, but i attached a screenshot of my prices(some above $1000) sorted by 100’s.

Also, i should mention that if you have anything priced over $10,000 , the price filter will sort by 1,000s. Over $100,000 will sort by 10,000s, etc.

Image Attachments
PriceBy100.gif
 
Magento Community Magento Community
Magento Community
Magento Community
 
mott
Member
 
Total Posts:  47
Joined:  2008-04-13
Los Angeles, CA
 

Sure I did all of the usual things. But the prices still were not parsed out like yours. I’m running 1.3.2.3.
Did you do anything different with your price attribute?

 
Magento Community Magento Community
Magento Community
Magento Community
 
NELAGeek
Sr. Member
 
Avatar
Total Posts:  193
Joined:  2010-01-23
US
 

My attributes are set like this:

searchable = yes
use in layered navigation = filterable(with results)

Image Attachments
PriceAttributes.gif
 
Magento Community Magento Community
Magento Community
Magento Community
 
mott
Member
 
Total Posts:  47
Joined:  2008-04-13
Los Angeles, CA
 

That’s what I have enabled. I’ll try on my test site and see if I get the same results. Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mpikounis
Member
 
Total Posts:  67
Joined:  2009-01-26
Athens, Greece
 

Hello,

I have been working on an alternative way of displaying the price filter so that I can avoid large groupings that are the default behavior for magento. I am not sure if this is any help to anyone, but I thought I should post it anyway:

I have overriden the file app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php in a local directory in order to override the following function:

protected function _getItemsData()
    
{
        $key 
$this->_getCacheKey();

        
$data $this->getLayer()->getAggregator()->getCacheData($key);
        if (
$data === null{
            $range      
5;// $this->getPriceRange();
            
$minEntries 10;

            
$dbRanges   $this->getRangeItemCounts($range);
            
$data       = array();

            
$collect 0;
            
$collectIndex 0;
            
$collections 1;
            
$lastIndex 0;
            foreach (
$dbRanges as $index=>$count{
                
if (( $collect $count ) >= $minEntries {
                        $collections 
$collectIndex == : ( $index $collectIndex ) + 1;
                        
$data[] = array(
                            
'label' => $this->_renderItemLabel($range $collections$index $collections),
                            
'value' => ( $index $collections ) . ',' $range $collections,
                            
'count' => $count $collect,
                        );
                        
$collect 0;
                        
$collections 1;
                        
$collectIndex 0;
                
else {
                        $collect 
$collect $count;
                        if ( 
$collectIndex == {
                                $collectIndex 
$index;
                        
}
                        $collections 
$collectIndex == $index : ( $index $collectIndex ) + 1;

                
}
                $lastIndex 
$index;
            
}
            
if ( $collect {
                      $data[] 
= array(
                           
'label' => $this->_renderItemLabel($range $collections$lastIndex $collections),
                           
'value' => ( $lastIndex $collections ) . ',' $range $collections,
                           
'count' => $collect,
                       );
            
}

            $tags 
= array(
                
Mage_Catalog_Model_Product_Type_Price::CACHE_TAG,
            );
            
$tags $this->getLayer()->getStateTags($tags);
            
$this->getLayer()->getAggregator()->saveCacheData($data$key$tags);
        
}
        
return $data;
    
}

Now by setting $range and $minEntries I can have a price filter that breaks up into $range but if a range does not have at least $minEntries products then it groups ranges together. You can see this working here: http://www.houseofwine.gr/how/wine.html

 
Magento Community Magento Community
Magento Community
Magento Community
 
mikefifield
Member
 
Avatar
Total Posts:  49
Joined:  2008-05-24
 

Does anyone know how to round the prices returned to the nearest dolor? For example one of the default price ranges looks like “ $200.00 to $300.00 (8) “ I would like this to look like “ $200 to $300 (8) “.

Thanks

Mike

 
Magento Community Magento Community
Magento Community
Magento Community
 
Darren Dub
Member
 
Total Posts:  35
Joined:  2010-03-11
 

floor

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jordan Harper
Jr. Member
 
Total Posts:  15
Joined:  2010-03-14
 

@jackiellowery

Great stuff—that function works a treat for what I needed it for (to stop Magento creating huge groups if there was a bit of variance in prices).

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ben Marks
Guru
 
Avatar
Total Posts:  452
Joined:  2008-10-09
Isle of Palms, SC
 

The seemed to work nicely for our client.  Might need some further logic for large collections or collections with max price > 10,000.

<?php

/**
 * Layer price filter - overridden for better price grouping when max price > 1000
 *
 * @category    Mage
 * @package   Mage_Catalog
 * @author      Ben Marks, Blue Acorn <support@blueacorn.com>
 */
class BlueAcorn_Catalog_Model_Layer_Filter_Price extends Mage_Catalog_Model_Layer_Filter_Price
{
    
/**
     * Get price range for building filter steps  - overridden for better price grouping when max price > 1000
     *
     * @return int
     */
    
public function getPriceRange()
    
{
        $range 
$this->getData('price_range');
        if (
is_null($range)) {
            $maxPrice 
$this->getMaxPriceInt();
            
$factor = ($maxPrice >= 1000)?5:10//adding this switch to prevent breaking products by 1000s
            
$index 1;
            do 
{
                $range 
pow($factor, (strlen(floor($maxPrice))-$index)); // - overridden to break up $1000 groups
                
$items $this->getRangeItemCounts($range);
                
$index++;
            
}
            
while($range>self::MIN_RANGE_POWER && count($items)<2);

            
$this->setData('price_range'$range);
        
}
        
return $range;
    
}
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
apexj
Jr. Member
 
Total Posts:  12
Joined:  2009-07-05
 

jackiellowery - Is it possible to adjust filter anything priced over $1,000, to have the price filter sort by 1,000s. So up to 1,000 filter by $100, then above $1,000 price filter by $1,000.

 
Magento Community Magento Community
Magento Community
Magento Community
 
karpik
Jr. Member
 
Total Posts:  15
Joined:  2008-08-06
Wakefield
 
mpikounis - 03 May 2010 07:39 AM

Hello,

I have been working on an alternative way of displaying the price filter so that I can avoid large groupings that are the default behavior for magento. I am not sure if this is any help to anyone, but I thought I should post it anyway:

I have overriden the file app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php in a local directory in order to override the following function:

protected function _getItemsData()
    
{
        $key 
$this->_getCacheKey();

        
$data $this->getLayer()->getAggregator()->getCacheData($key);
        if (
$data === null{
            $range      
5;// $this->getPriceRange();
            
$minEntries 10;

            
$dbRanges   $this->getRangeItemCounts($range);
            
$data       = array();

            
$collect 0;
            
$collectIndex 0;
            
$collections 1;
            
$lastIndex 0;
            foreach (
$dbRanges as $index=>$count{
                
if (( $collect $count ) >= $minEntries {
                        $collections 
$collectIndex == : ( $index $collectIndex ) + 1;
                        
$data[] = array(
                            
'label' => $this->_renderItemLabel($range $collections$index $collections),
                            
'value' => ( $index $collections ) . ',' $range $collections,
                            
'count' => $count $collect,
                        );
                        
$collect 0;
                        
$collections 1;
                        
$collectIndex 0;
                
else {
                        $collect 
$collect $count;
                        if ( 
$collectIndex == {
                                $collectIndex 
$index;
                        
}
                        $collections 
$collectIndex == $index : ( $index $collectIndex ) + 1;

                
}
                $lastIndex 
$index;
            
}
            
if ( $collect {
                      $data[] 
= array(
                           
'label' => $this->_renderItemLabel($range $collections$lastIndex $collections),
                           
'value' => ( $lastIndex $collections ) . ',' $range $collections,
                           
'count' => $collect,
                       );
            
}

            $tags 
= array(
                
Mage_Catalog_Model_Product_Type_Price::CACHE_TAG,
            );
            
$tags $this->getLayer()->getStateTags($tags);
            
$this->getLayer()->getAggregator()->saveCacheData($data$key$tags);
        
}
        
return $data;
    
}

Now by setting $range and $minEntries I can have a price filter that breaks up into $range but if a range does not have at least $minEntries products then it groups ranges together. You can see this working here: http://www.houseofwine.gr/how/wine.html

This works perfectly thank you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nelamurugan
Jr. Member
 
Avatar
Total Posts:  22
Joined:  2009-01-15
Chennai
 

@mpikounis is working for me,
but i want in different way,
like 0-20 $, 20 - 40 $
when it reaches 100 $
then it should be like 100 - 200 $, 200 - 300 $,
when it reaches 1000 $
then it will become 1000 - 2000 $ and more,
is it possible to modify this one?

Am using community edition 1.4.1

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 3