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);
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.
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.
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
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).
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.
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.
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?
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
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
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.