Today I have been knocking up a layered navigation option that is not based on an attribute. It is for ratings so the front end can show nice shiny stars.
To do this I have:
- Created a module
<blocks> <catalog> <rewrite> <layer_view>Bob_Catalog_Block_Layer_View</layer_view> </rewrite> </catalog> </blocks>
Created a class called Bob_Catalog_Block_Layer_View which extends Mage_Catalog_Block_Layer_View
- Created _initBlocks(), getFilters() and _prepareLayout() to override the parent classes methods. These all call the parent class at some point and then either prepend or appended extra data to what is returned.
- Create a filter block Bob_Catalog_Block_Layer_Filter_Rating which extends Mage_Catalog_Block_Layer_Filter_Abstract with a constructor that sets the filterModelName and calls its parent and then sets a custom template as it seems Mage_Catalog_Block_Layer_Filter_Abstract has the template name hardcoded in its constructor.
- Create a model Bob_Catalog_Model_Layer_Filter_Rating which extends Mage_Catalog_Model_Layer_Filter_Abstract and implements apply(), getName(), _getItemsData().
This all works fine. The nice shiny stars show in the layered nav.
I have a gut feeling that I'm missing something because when it comes to layer state template I've had to put a conditional in there to pick up the custom rating filter and alter the layout. Also some of the things I've needed to do (clone the product collection so that the load event doesn't screw up the collection counts on the pagination) make me feel like I've been swimming up hill.
So the question is have any of you got any better suggestions (or maybe a blog post wink) on how to build a custom non-attribute backed layered navigation filter?
Thanks for reading,