Try the Demo

Magento Forum

   
Page 1 of 4
shop by price - price range ? 
 
jay77
Member
 
Total Posts:  31
Joined:  2007-10-22
 

Hi,

is there any way to change the ‘shop by price’ default value by our own ?
because in my category, i have 60 products :

1 product at 25 usd
59 products under 10 usd

So i got this in my shopping option :

Price

1. $ 0.00 - $ 10.00 (59)
2. $ 20.00 - $ 30.00 (1)

i don’t think it’s very useful for the end user. Something like :

1. $ 0.00 - $ 2.00
2. $ 3.00 - $ 5.00
3. $ 6.00 - $ 10.00

would be much more useful.

thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
laurent
Member
 
Total Posts:  75
Joined:  2007-08-31
Paris, France
 

The price class is in app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php
You can try to replace 10 with 1 or 2 in this line:

$range pow(10, (strlen(floor($maxPrice))-$index));
It could suit your needs.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jay77
Member
 
Total Posts:  31
Joined:  2007-10-22
 

Merci Laurent, ça marche parfaitement !

 
Magento Community Magento Community
Magento Community
Magento Community
 
GregRandall
Jr. Member
 
Total Posts:  6
Joined:  2008-04-03
 

We’ve done a bit of a workaround in /Catalog/Model/Layer/Filter/Price.php to increase the minimum number of options (price ranges available) to 5, while also allowing for price range widths that are multiples of 20 or 50 rather than just 10.

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

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

 
Magento Community Magento Community
Magento Community
Magento Community
 
matt1237
Member
 
Avatar
Total Posts:  68
Joined:  2008-05-15
Washington State
 

**BEGIN EDIT** I removed this post as it no longer applies here. **END EDIT**

 Signature 

Looking for a professional web company that can deliver?  Check out our web design portfolio.

 
Magento Community Magento Community
Magento Community
Magento Community
 
DigitalSpring
Jr. Member
 
Total Posts:  14
Joined:  2008-10-22
 

Works great… thank you very much! grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
Calum Brodie
Jr. Member
 
Total Posts:  9
Joined:  2008-06-21
 

I hacked the File /Catalog/Model/Layer/Filter/Price.php
to deliver this functionality (see http://www.carrickwines.co.uk)

This will destroy the dynamic price navigation site wide and replace it with these static price levels. Also this is not tested with anything other than simple products in one currency.
The code is quite messy and convoluted - but it works.

Replace this (line 161)

foreach ($dbRanges as $index=>$count{
                $data[] 
= array(
                    
'label' => $this->_renderItemLabel($range$index),
                    
'value' => $index ',' $range,
                    
'count' => $count,
                );
            
}

with this - edit the values as you need. Remember to refresh both the overall cache (cache>>refresh) and layered caches (refresh layered navigation) in cache management to see your changes.

///////// 0-5 ///////////////////////
                $count_first  $this->getRangeItemCounts(5);
                
$count_first_value = (array_key_exists(1$count_first)) ? $count_first[1]:0;    
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(51),
                    
'value' => ',' 5,
                    
'count' => $count_first_value,
                );
    
///////// 5-7 ///////////////////////            
                
$count_second  $this->getRangeItemCounts(1);
                
$count_second_value 0;
                
$count_second_value += 
                (
array_key_exists(6$count_second)) ? $count_second[6]:0;
                
$count_second_value +=
                (
array_key_exists(7$count_second)) ? $count_second[7]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(23.5),
                    
'value' => 3.5 ',' 2,
                    
'count' => $count_second_value,
                );

    
///////// 7-11 ///////////////////////            
                
$count_third   $this->getRangeItemCounts(1);
                
$count_third_value 0;
                
$count_third_value += 
                (
array_key_exists(8$count_third)) ? $count_third[8]:0;
                
$count_third_value += 
                (
array_key_exists(9$count_third)) ? $count_third[9]:0;
                
$count_third_value += 
                (
array_key_exists(10$count_third)) ? $count_third[10]:0;
                
$count_third_value += 
                (
array_key_exists(11$count_third)) ? $count_third[11]:0;                
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(42.75),
                    
'value' => 2.75 ',' 4,
                    
'count' => $count_third_value,
                );

    
///////// 11-15 ///////////////////////
                
$count_fourth   $this->getRangeItemCounts(1);
                
$count_fourth_value 0;
                
$count_fourth_value += 
                (
array_key_exists(12$count_fourth)) ? $count_fourth[12]:0;
                
$count_fourth_value += 
                (
array_key_exists(13$count_fourth)) ? $count_fourth[13]:0;
                
$count_fourth_value += 
                (
array_key_exists(14$count_fourth)) ? $count_fourth[14]:0;
                
$count_fourth_value += 
                (
array_key_exists(15$count_fourth)) ? $count_fourth[15]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(43.75),
                    
'value' => 3.75 ',' 4,
                    
'count' => $count_fourth_value,
                );
    
    
///////// 15-20 ///////////////////////            
                
$count_fifth   $this->getRangeItemCounts(5);
                
$count_fifth_value 0;
                
$count_fifth_value += (array_key_exists(4$count_fifth)) ? $count_fifth[4]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(54),
                    
'value' => ',' 5,
                    
'count' => $count_fifth_value,
                    );

There are obviously more for my page but you will get the idea. The if statements are there to stop Magento throwing errors when you don’t have any items in that price range. Some statements are easier than others - for example 15-20 only needs to count one range (the fourth index of range 5) whereas 11-15 is more complicated - I had to add 4 separate values ( the 12th - 15th index of range 1) - this is the only way I could think of to get the count working correctly.

You then may wish to add some logic to stop the range displaying if the count is 0 - not shown

 
Magento Community Magento Community
Magento Community
Magento Community
 
BruceM
Jr. Member
 
Total Posts:  16
Joined:  2008-11-02
 

We’ve done a bit of a workaround in /Catalog/Model/Layer/Filter/Price.php to increase the minimum number of options (price ranges available) to 5, while also allowing for price range widths that are multiples of 20 or 50 rather than just 10.

thx @Greg Randall this one worked for me! (on 1.3.1)

Shame I have to change core code - but the current automated price ranges were making absolutely no sense (100+ products in $0-100 range and 3 products in $100-200 range).

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendanb
Mentor
 
Total Posts:  1072
Joined:  2008-07-16
London, United Kingdom
 

hey bruce,

you could put this file out to the local directory that way it doesnt effect core

for example create the following folder structure under the app/code/local/Mage/Catalog/Model/Layer/Filter/Price.php

brendan

 Signature 

Magento Enterprise & Community Developer

 
Magento Community Magento Community
Magento Community
Magento Community
 
BruceM
Jr. Member
 
Total Posts:  16
Joined:  2008-11-02
 

yep that worked! thx @brendan.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rajbrades
Member
 
Total Posts:  53
Joined:  2007-09-04
 

Rather than $0 - $x, is there some way to have “less than $x”? I don’t like seeing the “$0” in there.

 
Magento Community Magento Community
Magento Community
Magento Community
 
pro120
Jr. Member
 
Total Posts:  15
Joined:  2008-11-10
 
Calum Brodie - 26 March 2009 05:38 AM

I hacked the File /Catalog/Model/Layer/Filter/Price.php
to deliver this functionality (see http://www.carrickwines.co.uk)

This will destroy the dynamic price navigation site wide and replace it with these static price levels. Also this is not tested with anything other than simple products in one currency.
The code is quite messy and convoluted - but it works.

Replace this (line 161)

foreach ($dbRanges as $index=>$count{
                $data[] 
= array(
                    
'label' => $this->_renderItemLabel($range$index),
                    
'value' => $index ',' $range,
                    
'count' => $count,
                );
            
}

with this - edit the values as you need. Remember to refresh both the overall cache (cache>>refresh) and layered caches (refresh layered navigation) in cache management to see your changes.

///////// 0-5 ///////////////////////
                $count_first  $this->getRangeItemCounts(5);
                
$count_first_value = (array_key_exists(1$count_first)) ? $count_first[1]:0;    
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(51),
                    
'value' => ',' 5,
                    
'count' => $count_first_value,
                );
    
///////// 5-7 ///////////////////////            
                
$count_second  $this->getRangeItemCounts(1);
                
$count_second_value 0;
                
$count_second_value += 
                (
array_key_exists(6$count_second)) ? $count_second[6]:0;
                
$count_second_value +=
                (
array_key_exists(7$count_second)) ? $count_second[7]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(23.5),
                    
'value' => 3.5 ',' 2,
                    
'count' => $count_second_value,
                );

    
///////// 7-11 ///////////////////////            
                
$count_third   $this->getRangeItemCounts(1);
                
$count_third_value 0;
                
$count_third_value += 
                (
array_key_exists(8$count_third)) ? $count_third[8]:0;
                
$count_third_value += 
                (
array_key_exists(9$count_third)) ? $count_third[9]:0;
                
$count_third_value += 
                (
array_key_exists(10$count_third)) ? $count_third[10]:0;
                
$count_third_value += 
                (
array_key_exists(11$count_third)) ? $count_third[11]:0;                
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(42.75),
                    
'value' => 2.75 ',' 4,
                    
'count' => $count_third_value,
                );

    
///////// 11-15 ///////////////////////
                
$count_fourth   $this->getRangeItemCounts(1);
                
$count_fourth_value 0;
                
$count_fourth_value += 
                (
array_key_exists(12$count_fourth)) ? $count_fourth[12]:0;
                
$count_fourth_value += 
                (
array_key_exists(13$count_fourth)) ? $count_fourth[13]:0;
                
$count_fourth_value += 
                (
array_key_exists(14$count_fourth)) ? $count_fourth[14]:0;
                
$count_fourth_value += 
                (
array_key_exists(15$count_fourth)) ? $count_fourth[15]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(43.75),
                    
'value' => 3.75 ',' 4,
                    
'count' => $count_fourth_value,
                );
    
    
///////// 15-20 ///////////////////////            
                
$count_fifth   $this->getRangeItemCounts(5);
                
$count_fifth_value 0;
                
$count_fifth_value += (array_key_exists(4$count_fifth)) ? $count_fifth[4]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(54),
                    
'value' => ',' 5,
                    
'count' => $count_fifth_value,
                    );

There are obviously more for my page but you will get the idea. The if statements are there to stop Magento throwing errors when you don’t have any items in that price range. Some statements are easier than others - for example 15-20 only needs to count one range (the fourth index of range 5) whereas 11-15 is more complicated - I had to add 4 separate values ( the 12th - 15th index of range 1) - this is the only way I could think of to get the count working correctly.

You then may wish to add some logic to stop the range displaying if the count is 0 - not shown

Could anyone give me a quick run down of the coding and how to change the price range variables?  Seems like there is a wierd workaround in this for totaling the products correctly that makes it hard to just change the variables.  I dont have enough experience editing code like this but I learn quick.  Anyone?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Calum Brodie
Jr. Member
 
Total Posts:  9
Joined:  2008-06-21
 

there are two things you have to change.

First the label and link are changed by editing the following

'label' => $this->_renderItemLabel(51),
                    
'value' => ',' 5,

this means the first index of the range 5 (0-5). If you wanted to get items between 12-8 for example you would change to

‘label’ => $this->_renderItemLabel(6, 3),
‘value’ => 3. ‘,’ . 6,

The second (more complicated part) is to count the number of products in that range.

This is easy if you are only using whole numbers for your multiplier (the 1 or 3 in the above examples) In which case you would simply enter the variables into magento’s built in count function and it would give you the correct result.... ie

$count_first  $this->getRangeItemCounts(5);
                
$count_first_value = (array_key_exists(1$count_first)) ? $count_first[1]:0;

translation:
1st line says --->> use the range of 5
2nd line says--> use only the first index in that range

if you wanted 6-18 you would change to

$count_first  $this->getRangeItemCounts(6);
                
$count_first_value = (array_key_exists(3$count_first)) ? $count_first[3]:0;

If you want to use a multiple that is NOT a whole number then you need to concatenate multiple ranges… I will explain the following code

///////// 5-7 ///////////////////////            
                $count_second  $this->getRangeItemCounts(1);
                
$count_second_value 0;
                
$count_second_value += 
                (
array_key_exists(6$count_second)) ? $count_second[6]:0;
                
$count_second_value +=
                (
array_key_exists(7$count_second)) ? $count_second[7]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(23.5),
                    
'value' => 3.5 ',' 2,
                    
'count' => $count_second_value,
                );

translation:
Use the range of one

then take to 6th and seventh indexes of that range and add them together (6th index is items in the range 5-6 and 7th index is items in the range 6-7).

You need to do it this way becasue:

$this->getRangeItemCounts()

only accepts whole numbers. If you try and use ca value with a decimal point (3.5) it will round it to the nearest whole number giving you the wrong output.

Good Luck, post your code if you’re still having trouble

 
Magento Community Magento Community
Magento Community
Magento Community
 
hongsungkim
Jr. Member
 
Total Posts:  11
Joined:  2009-03-23
 

I’ve benn looking for this all over.  Thank you so much!!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Herve Guetin
Sr. Member
 
Avatar
Total Posts:  216
Joined:  2008-05-10
Paris, FR
 

Hi all,

On my side, I’m trying to retrieve the max price but from the template/catalog/layer/filter.phtml file in order to use the value in javascript.
I’ve tried loads of Mage::getModel, Mage::getSingleton… but I am not able to point to the public function getMaxPriceInt() in Price.php

Can you help me figure out what I’m missing here please ?
Thanks a lot.

 Signature 

Magento Certified Developer
Developer Profile : http://www.magentocommerce.com/certification/directory/dev/4650/

 
Magento Community Magento Community
Magento Community
Magento Community
 
aeroplane10
Jr. Member
 
Avatar
Total Posts:  11
Joined:  2009-04-16
 

I’m having trouble Calum Brodie!
I would like to use your code but I don’t know how to change the vars to use it with the following range table:

$ 0.00 - $ 50.00
$ 51 - $ 100.00
$ 101 - $ 200.00
$ 201 - $ 500.00
$ 501 - $ 1000.00
$ 1001 - $ 3000.00

Thanks!!

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