Magento Forum

   
shop by price - price range ? 
 
Amasty
Mentor
 
Avatar
Total Posts:  3769
Joined:  2009-11-10
 

Hello,

You can create custom price ranges for layered navigation with Improved Navigation extension and update them when needed without having to edit code. Please see http://www.magentocommerce.com/magento-connect/Amasty/extension/2685/improved-navigation for more info. Your comments welcome.

 
Magento Community Magento Community
Magento Community
Magento Community
 
webarton
Member
 
Total Posts:  45
Joined:  2011-02-03
 

Thank you very much for sharing, deggertsen!

I need to modify but I can’t. I’m trying to have a price range as below,

1. ¥0 - ¥300
2. ¥300 - ¥500
3. ¥500 - ¥1,000
4. ¥1,000 - ¥5,000
5. ¥5,000 - ¥10,000
6. ¥10,000 - ¥50,000
7. ¥50,000 - ¥100,000
8. ¥100,000 - ¥200,000

I’m writing like this. Could anyone tell me how I can fix it?

///////// 0-300 ///////////////////////
                $count_first  $this->getRangeItemCounts(300);
                
$count_first_value = (array_key_exists(1$count_first)) ? $count_first[1]:0;    
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(3001),
                    
'value' => ',' 300,
                    
'count' => $count_first_value,
                );

    
///////// 300-500 ///////////////////////
                
$count_second  $this->getRangeItemCounts(100);
                
$count_second_value 0;
                
$count_second_value += 
                (
array_key_exists(2$count_second)) ? $count_second[2]:0;    
                
$count_second_value += 
                (
array_key_exists(3$count_second)) ? $count_second[3]:0;    
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(1005),
                    
'value' => ',' 100,
                    
'count' => $count_second_value,
                );

    
///////// 500-1000 ///////////////////////
                
$count_third  $this->getRangeItemCounts(500);
                
$count_third_value = (array_key_exists(2$count_third)) ? $count_third[2]:0;    
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(5002),
                    
'value' => ',' 500,
                    
'count' => $count_third_value,
                );
                
    
///////// 1000-5000 ///////////////////////            
                
$count_fourth   $this->getRangeItemCounts(1000);
                
$count_fourth_value 0;
                
$count_fourth_value += 
                (
array_key_exists(2$count_fourth)) ? $count_fourth[2]:0;
                
$count_fourth_value += 
                (
array_key_exists(3$count_fourth)) ? $count_fourth[3]:0;
                
$count_fourth_value += 
                (
array_key_exists(4$count_fourth)) ? $count_fourth[4]:0;
                
$count_fourth_value += 
                (
array_key_exists(5$count_fourth)) ? $count_fourth[5]:0;
                
$count_fourth_value += 
                (
array_key_exists(6$count_fourth)) ? $count_fourth[6]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(50001),
                    
'value' => ',' 5000,
                    
'count' => $count_fourth_value,
                    );

    
///////// 5000-10000 ///////////////////////            
                
$count_fifth   $this->getRangeItemCounts(1000);
                
$count_fifth_value 0;
                
$count_fifth_value += 
                (
array_key_exists(2$count_fifth)) ? $count_fifth[2]:0;
                
$count_fourth_value += 
                (
array_key_exists(3$count_fourth)) ? $count_fourth[3]:0;
                
$count_fourth_value += 
                (
array_key_exists(4$count_fourth)) ? $count_fourth[4]:0;
                
$count_fourth_value += 
                (
array_key_exists(5$count_fourth)) ? $count_fourth[5]:0;
                
$count_fourth_value += 
                (
array_key_exists(6$count_fourth)) ? $count_fourth[6]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(50002),
                    
'value' => ',' 5000,
                    
'count' => $count_fifth_value,
                    );

    
///////// 10000-50000 ///////////////////////            
                
$count_sixth   $this->getRangeItemCounts(10000);
                
$count_sixth_value 0;
                
$count_sixth_value += 
                (
array_key_exists(2$count_sixth)) ? $count_sixth[2]:0;
                
$count_sixth_value += 
                (
array_key_exists(3$count_sixth)) ? $count_sixth[3]:0;
                
$count_sixth_value += 
                (
array_key_exists(4$count_sixth)) ? $count_sixth[4]:0;
                
$count_sixth_value += 
                (
array_key_exists(5$count_sixth)) ? $count_sixth[5]:0;
                
$count_sixth_value += 
                (
array_key_exists(6$count_sixth)) ? $count_sixth[6]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(100005),
                    
'value' => ',' 10000,
                    
'count' => $count_sixth_value,
                    );

    
///////// 50000-100000 ///////////////////////            
                
$count_seventh   $this->getRangeItemCounts(50000);
                
$count_seventh_value 
                (
array_key_exists(2$count_seventh)) ? $count_seventh[2]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(500002),
                    
'value' => ',' 50000,
                    
'count' => $count_seventh_value,
                    );

    
///////// 100000-200000 ///////////////////////            
                
$count_eigth   $this->getRangeItemCounts(100000);
                
$count_eigth_value 
                (
array_key_exists(2$count_eigth)) ? $count_eigth[2]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(1000002),
                    
'value' => ',' 100000,
                    
'count' => $count_eigth_value,

Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
 
webarton
Member
 
Total Posts:  45
Joined:  2011-02-03
 

Sorry, this is an additional post. I couldn’t add this because of the character limit.

My price range is currently shown like this;

1. ¥0 - ¥300 (23)
2. ¥400 - ¥500 (12)
3. ¥500 - ¥1,000 (5)
4. ¥0 - ¥5,000 (6)
5. ¥5,000 - ¥10,000 (2)
6. ¥40,000 - ¥50,000 (0)
7. ¥50,000 - ¥100,000 (0)
8. ¥100,000 - ¥200,000 (0)

Thank you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Amasty
Mentor
 
Avatar
Total Posts:  3769
Joined:  2009-11-10
 

Have you already tried the Improved Navigation plugin? It does exactly what you are asking for. We are open for customization if you like to modify some aspects of the solution.

 
Magento Community Magento Community
Magento Community
Magento Community
 
webtainment
Jr. Member
 
Total Posts:  21
Joined:  2011-01-17
 

well - the most easiest way is to simply edit the price.php in app/code/core/Mage/Catalog/Model/Layer/Filter/

Of course this ain`t update-proof. but if you update you can easily change it again.

The price-range is calculated as follows:

$range pow([color=red]CUSTOM NUMBER[/color], (strlen(floor($maxPrice))-$index));
                
$items $this->getRangeItemCounts($range);
                
$index++;[code]

where CUSTOM NUMBER should be the extracted root of the price-step you want to have.

Example:

By default the value is 10 - means the steps are in 100 USD (10 is the extracted root of 100)
If you want to have steps of 5 then you should enter: 2.236067977499789 (which is the extracted root of 5)
If you want to have steps of 6,25 then you should enter: 2,5
If you want to have steps of 10 you should enter: 3.1622776601

I didn`t test how many digits after the decimal-point are needed - check it our yourselves wink This is an absolute idiotic solution - but it works wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
webarton
Member
 
Total Posts:  45
Joined:  2011-02-03
 

Thank you webtainment!  I think your solution is the best way if the price range is based by steps of the same number.

But in my case, I’d like to have a price range like this;

1. ¥0 - ¥300
2. ¥300 - ¥500
3. ¥500 - ¥1,000
4. ¥1,000 - ¥5,000
5. ¥5,000 - ¥10,000
6. ¥10,000 - ¥50,000
7. ¥50,000 - ¥100,000
8. ¥100,000 - ¥200,000

I thought I can’t get like this if I modify $range = pow(10, (strlen(floor($maxPrice)) - $index));. Am I wrong?

Thank you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
webarton
Member
 
Total Posts:  45
Joined:  2011-02-03
 

I’m sorry again. I could fix the price range as I want to show, but some products are in a wrong price range. I looked the code over and over but I have no idea how to fix it any more.

Could anyone help me please?

///////// 0-300 ///////////////////////
                $count_first  $this->getRangeItemCounts(300);
                
$count_first_value = (array_key_exists(1$count_first)) ? $count_first[1]:0;    
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(3001),
                    
'value' => ',' 300,
                    
'count' => $count_first_value,
                );

    
///////// 300-500 ///////////////////////
                
$count_second  $this->getRangeItemCounts(100);
                
$count_second_value 0;
                
$count_second_value += 
                (
array_key_exists(2$count_second)) ? $count_second[2]:0;    
                
$count_second_value += 
                (
array_key_exists(3$count_second)) ? $count_second[3]:0;    
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(2002.5),
                    
'value' => 2.5 ',' 200,
                    
'count' => $count_second_value,
                );

    
///////// 500-1000 ///////////////////////
                
$count_third  $this->getRangeItemCounts(500);
                
$count_third_value = (array_key_exists(2$count_third)) ? $count_third[2]:0;    
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(5002),
                    
'value' => ',' 500,
                    
'count' => $count_third_value,
                );
                
    
///////// 1000-5000 ///////////////////////            
                
$count_fourth   $this->getRangeItemCounts(1000);
                
$count_fourth_value 0;
                
$count_fourth_value += 
                (
array_key_exists(2$count_fourth)) ? $count_fourth[2]:0;
                
$count_fourth_value += 
                (
array_key_exists(3$count_fourth)) ? $count_fourth[3]:0;
                
$count_fourth_value += 
                (
array_key_exists(4$count_fourth)) ? $count_fourth[4]:0;
                
$count_fourth_value += 
                (
array_key_exists(5$count_fourth)) ? $count_fourth[5]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(40001.25),
                    
'value' => 1.25 ',' 4000,
                    
'count' => $count_fourth_value,
                    );

    
///////// 5000-10000 ///////////////////////            
                
$count_fifth   $this->getRangeItemCounts(5000);
                
$count_fifth_value = (array_key_exists(2$count_fifth)) ? $count_fifth[2]:0;  
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(50002),
                    
'value' => ',' 5000,
                    
'count' => $count_fifth_value,
                    );

    
///////// 10000-50000 ///////////////////////            
                
$count_sixth   $this->getRangeItemCounts(10000);
                
$count_sixth_value 0;
                
$count_sixth_value += 
                (
array_key_exists(2$count_sixth)) ? $count_sixth[2]:0;
                
$count_sixth_value += 
                (
array_key_exists(3$count_sixth)) ? $count_sixth[3]:0;
                
$count_sixth_value += 
                (
array_key_exists(4$count_sixth)) ? $count_sixth[4]:0;
                
$count_sixth_value += 
                (
array_key_exists(5$count_sixth)) ? $count_sixth[5]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(400001.25),
                    
'value' => 1.25 ',' 40000,
                    
'count' => $count_sixth_value,
                    );

    
///////// 50000-100000 ///////////////////////            
                
$count_seventh   $this->getRangeItemCounts(50000);
                
$count_seventh_value 
                (
array_key_exists(2$count_seventh)) ? $count_seventh[2]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(500002),
                    
'value' => ',' 50000,
                    
'count' => $count_seventh_value,
                    );

    
///////// 100000-200000 ///////////////////////            
                
$count_eigth   $this->getRangeItemCounts(100000);
                
$count_eigth_value 
                (
array_key_exists(2$count_eigth)) ? $count_eigth[2]:0;
                
$data[] = array(
                    
'label' => $this->_renderItemLabel(1000002),
                    
'value' => ',' 100000,
                    
'count' => $count_eigth_value,
                    );

 
Magento Community Magento Community
Magento Community
Magento Community
 
webarton
Member
 
Total Posts:  45
Joined:  2011-02-03
 
jackthomson - 21 March 2011 04:38 AM

This wide dynamic price change with this static navigation on the site does not exist and the price levels.

I’m sorry jackthomson, I don’t get what you mean… Do you mean what I’m doing is impossible?

 
Magento Community Magento Community
Magento Community
Magento Community
 
webarton
Member
 
Total Posts:  45
Joined:  2011-02-03
 

Sorry again, I think my website is showing the price range as below correctly.

1. ¥0 - ¥300
2. ¥300 - ¥500
3. ¥500 - ¥1,000
4. ¥1,000 - ¥5,000
5. ¥5,000 - ¥10,000
6. ¥10,000 - ¥50,000
7. ¥50,000 - ¥100,000
8. ¥100,000 - ¥200,000

jackthomson - 21 March 2011 04:38 AM

Also, this is not in the currency of anything except the simple products.

I found there are some products which are not categorized in simple products. I understand they won’t be counted. Thank you jackthomson!

 
Magento Community Magento Community
Magento Community
Magento Community
 
liszak
Jr. Member
 
Total Posts:  1
Joined:  2010-08-25
 
mauricioprado00 - 16 December 2009 06:12 AM

[ this solution is for an old version of magento 1.3 i believe i cant remember, ill update to implement the same in a newer version but the basic difference is that instead $items[] = $this->_createItem would be something like $data[] = array(.... but ive to check it ]
deggertsen have the perfect solution. The only drawback is that is hard to calculate the counts every time you rearrange the price rankss. so i made an algorithm programmed for the analitic solution to generate ranks.
instead to do what deggertsen does, you could just do this:

$this->_items $this->getItemsByRanks($this->amps_to_ranks(array(25,25,50,50,50,200,600,5000)));
or this:
$this->_items $this->getItemsByRanks($this->boundaryes_to_ranks(array(0255010015020040010006000)));
or this:
$this->_items $this->getItemsByRanks(array(
    array(
025),
    array(
2550),
    array(
50100),
    array(
100150),
    array(
150200),
    array(
200400),
    array(
4001000),
    array(
10006000),
));
and the results would be exaclty the same

here is the methods that suport to do something like that and you just have to add to Mage_Catalog_Model_Layer_Filter_Price, and as you can see in the line
if(!$rank_count)continue;

when a rank does not contains a result it will be not showed:

private function amps_to_ranks($amps$start_price=0){
                $ranks 
= array();
                foreach(
$amps as $amp)
                        
$ranks[] = array($start_price$start_price $start_price+$amp);
                return(
$ranks);
        
}
        
private function boundaryes_to_ranks($boundaryes){
                $ranks 
= array();
                
$first array_shift($boundaryes);
                foreach(
$boundaryes as $boundary){
                        $ranks[] 
= array($first$first $boundary);
                
}
                
return($ranks);
        
}
        
private function find_div($min$div$fixed_jumps=null){
                $orig_div 
$div;
                
$prime_numbers = array(2,3,5,7,11,13,17,23);//here you could add a larger amount of prime numbers, depends on how complex will be your ranks, this should be fine
                
while(($min%$div)!==0){
                        $current_jump 
= isset($fixed_jumps)&&count;($fixed_jumps)?array_pop($fixed_jumps):0;
                        foreach(
$prime_numbers as $idx=>$prime_number)
                                if(
$current_jump<=$idx&&!($div%$prime_number)){
                                        $div 
$div $prime_number;
                                        break;
                                
}
                        
if($div===$orig_div)
                                break;
                
}
                
return($div);
        
}
        
private function best_div($min$div){
                $jumps 
= array(0,1,2,3,4);
                
$arr_jumps = array();
                foreach(
$jumps as $i)
                        foreach(
$jumps as $j)
                                if(
$i || $j)
                                        
$arr_jumps[] = array($i$j);
                
$orig_div $div;
                
$found_divs = array();
                
$new_div $this->find_div($min$div);
                if(
$orig_div!=$new_div)
                        
$found_divs[] $new_div;
                foreach(
$arr_jumps as $jumps){
                        $new_div 
$this->find_div($min$div$jumps);
                        if(
$new_div!=$orig_div)
                                
$found_divs[$jumps[0].','.$jumps[1]] $new_div;
                
}
                $best_div 
$orig_div;
                if(
$found_divs)
                        
$best_div max($found_divs);
                return(
$best_div);
        
}
        
private function getItemsByRanks($ranks){
//var_dump($ranks);die();
                
$interval_counts = array();
                
$items = array();
                foreach(
$ranks as $rank){
                        $min 
$rank[0];
                        
$max $rank[1];
                        
$amp $max $min;
                        
$div $amp;
                        
$div $this->best_div($min$div);
                        if(
$min%$div)//wont be able to find the count without a divisor so stop here
                                
continue;
                        if(!isset(
$interval_counts[$div])){
                                $interval_counts[$div] 
$this->getRankItemCounts($div);//cache results
                        
}
                        $rank_count 
0;
                        
$istart $min $div;
                        
$iend $istart $amp $div;
                        for(
$i=$istart$i<$iend$i++){
                                
if(isset($interval_counts[$div][$i+1]))
                                        
$rank_count += $interval_counts[$div][$i+1];
                        
}
                        
if(!$rank_count)continue;
                        
$idx $max $amp;

                        
$count $rank_count;
                        
$label $this->_renderItemLabel($amp$idx);
                        
$value $idx ',' $amp;
                        
$items[] $this->_createItem(
                                
$label,
                                
$value,
                                
$count
                        
);

                
}
                
return($items);
        
}

better functions:

private function best_div($min$max){
  
while($min && $max)
  if(
$max>$min)
    
$max -= $min;
  else
    
$min -= $max;
  if(
$min)
    return 
$min;
  return 
$max;
}
and call:
$div $this->best_div($min$max);

 
Magento Community Magento Community
Magento Community
Magento Community
 
shiwak224
Member
 
Total Posts:  41
Joined:  2011-03-23
 

Hi, I have price range from 0 - 10000 can anyone help me??
I try to use code given by greg in first page then I got some error.
Need help !!!
I am using magento 1.5.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sunil.talekar
Jr. Member
 
Total Posts:  2
Joined:  2010-11-09
 

I Found the solution by which you can easily Change the price range and make it whatever you want to set

this is a very simple formula check it

Requirements
---------------------------

1) Minimum Range

2) Maxinum Range

3) Difference = Maxinum - Minimum

Calculation
-------------------------

STEP 1:  Result = Minimum / Difference

STEP 2 : Minimum = Result * Difference

STEP 3: Maximum = ( Result + 1 ) * Difference

STEP 4: value = Result + 1

So, Your Final URL will be :  http://www.yoursite.com/your_category.html/?price=value,Difference

Hope This will help you!!!!!!!!!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
zhenyew
Jr. Member
 
Total Posts:  5
Joined:  2011-06-07
 

public function getPriceRange()
{

$range = $this->getData(’price_range’);
if (!$range) {
/* << command
$currentCategory = Mage::registry(’current_category_filter’);
if ($currentCategory) {
$range = $currentCategory->getFilterPriceRange();
} else {
$range = $this->getLayer()->getCurrentCategory()->getFilterPriceRange();
}

$maxPrice = $this->getMaxPriceInt();
if (!$range) {
$calculation = Mage::app()->getStore()->getConfig(self::XML_PATH_RANGE_CALCULATION);
if ($calculation == self::RANGE_CALCULATION_AUTO) {
$index = 1;
do {
$range = pow(10, (strlen(floor($maxPrice)) - $index));
$items = $this->getRangeItemCounts($range);
$index++;
}
while($range > self::MIN_RANGE_POWER && count($items) < 2);
} else {
$range = Mage::app()->getStore()->getConfig(self::XML_PATH_RANGE_STEP);
}
}

while (ceil($maxPrice / $range) > 25) {
$range *= 10;
}
*/<< command
$range = 50; //custom range of $0 - $50, $50 - $100, $50 - $100, $100 - $150 and so forth, you can set any number
$this->setData(’price_range’, $range);
}

return $range;
}

*see attachment

Image Attachments
pricerange.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
designer84
Sr. Member
 
Total Posts:  102
Joined:  2009-08-20
 

Simply go to your admin area and change it there…

1. Go to System > Configuration > Catalog (under Catalog) > Layered Navigation
2. Change the Price Navigation Step Calculation dropdown from Automatic to Manual
3. Enter the amount you want it to be (e.g. - 50) into the Default Price Navigation Step input box
4. Save

Viola!

Image Attachments
Screen Shot 2012-03-16 at 4.20.29 PM.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
zhenyew
Jr. Member
 
Total Posts:  5
Joined:  2011-06-07
 
designer84 - 16 March 2012 02:25 PM

Simply go to your admin area and change it there…

1. Go to System > Configuration > Catalog (under Catalog) > Layered Navigation
2. Change the Price Navigation Step Calculation dropdown from Automatic to Manual
3. Enter the amount you want it to be (e.g. - 50) into the Default Price Navigation Step input box
4. Save

Viola!

Tested at the very beginning…
if you have product price range 0 - 450, set Price Navigation Step Calculation to Manual, and insert range should solve it.
but If you have a product price few times x greater than the price range 0 - 450, e.g 8900. You can see what happen in my attachment… lol!

Image Attachments
manualfk.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top