3

How to make a custom attribute in magento to show as range in layered navigation like price any ideas please help

  • guys any help on this please – Bharath Jul 7 '14 at 7:23
7

So in principle what you will need to do is create your own model for the filter and then in this model create a function _getItemsData. This function will create all the filter items that need to be shown, in your case the different ranges. Each item should be in the following format.

$data[] = array(
    'label' => 'String To show for the filter',
    'value' => $fromValue . '-' . $toValue,
    'count' => 'How many items are in this range',
);

When you create a filter block you can attach a model for calulating it's data via $this->_filterModelName = 'your/layer_filter_model';

How to add new filters I am not completely sure but once that has been sorted the key is getting the data items. You can look into how the price filter works and mirror this.

  • 1
    Thanks for your suggestion david.What i did is select type as price when creating new attribute. That worked for me a bit. – Bharath Mar 18 '15 at 20:53
  • 3
    @Magesavvy welcome back to the site! You should make your solution an answer if possible so others can more accurately see what you've done :D – easymoden00b Mar 19 '15 at 12:39
0

You can accomplish this with the Improved Layered Navigation extension.

To create a new numeric attribute (e.g. length, width, height) please follow these steps:

  1. Go to admin panel > Catalog > Attributes > Manage Attributes > Create New
  2. Choose catalog input type ‘Price’ for numeric attributes if you would like to use sliders for them.
  3. Set the ‘Use in Layered Navigation’ option to ‘Filterable’.
  4. Once you create the ‘price’ attributes please go to Catalog > Improved Navigation > Filters and click ‘Load’ button. After that, the numeric attributes will appear in the list of filters.
  • I see this exact comment on almost all related questions. How much kickback from Amasty are you getting? :/ Agreed, it is an option for plug-and-play usage, but some (most?) of us here are developers, and probably building some tailor-made stuff. Spamming all questions with ads to paid solutions isn't really helping. – Alex Timmer Dec 11 '17 at 13:07
  • @AlexTimmer, if you feel like writing your own custom code makes you a better developer, that's fine. For my clients, I try to give them the best option for their money. If I can spend $100 for an extension that does what they need versus charging them $1,000 for a custom one, I'm not going to steal $900 from my client just to make myself feel more accomplished. There's a right time for everything & sometimes a 3rd-party extension isn't the best option. But, I leave my answers so those in need can determine what's best for them. Blatantly illogical comments about "spam" definitely don't help! – Michael Yaeger Dec 11 '17 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.