3

I am using dropdowns to display my layered navigation attribute values. I have 3 filters - price, size and color. This is what I am trying to do: 1. Get dropdowns for the layered navigation filters. 2. Get the attribute label/name to show up as the first option. Currently, my code puts a default "Choose an Option" value for each dropdown, which I would like to replace with something like "Choose Price", "Choose Size" and "Choose Color". Here is my current code for template/catalog/layer/filter.phtml. The dropdown works, but I am stuck at getting the attribute label instead of "Choose an Option"

<select onchange="setLocation(this.value)">
<option value='' disabled selected style='display:none;'>Choose an Option</option>
</option> 
<?php foreach ($this->getItems() as $_item): ?>
<option
    <?php if ($_item->getCount() > 0): ?>
    value="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?>
    <?php else: echo '>' . $_item->getLabel() ?>
    <?php endif; ?>
    (<?php echo $_item->getCount() ?>)
</option>

GKRP
  • 85
  • 2
  • 10
  • Can you please give more details on how you managed to use dropdowns instead of native `` filters? – Hervé Guétin Sep 12 '12 at 11:08
  • Ok, the "Choose an Option" was not present in the default filter.phtml. Posting the old and new code in my question. – GKRP Sep 12 '12 at 12:03
  • Vote to close: installation specific, not generic for Magento questions. Cannot you just grep your files for the text to find out where it originates from? – Theodores Sep 12 '12 at 12:03
  • Well, I am trying to solve what should be a simple issue - get the attribute values in a dropdown, and then show the label as the default option. I got the first part from one of the boards, and am trying to figure out how to do the second. I am sure a lot of people would be interested in a solution :) – GKRP Sep 12 '12 at 12:38

1 Answers1

2

Try this code. It is tested in all the browsers.

<select onchange="setLocation(this.value)">
<?php $count = 0; ?>
 <?php foreach ($this->getItems() as $_item): ?> 
 <?php $count++; ?>
 <?php if($count == 1): ?>
<option value='' disabled selected style='display:none;'>Choose <?php echo $attribute_code = $_item->getFilter()->getName();?> </option> 
<?php endif; ?>
<option <?php if ($_item->getCount() > 0): ?> value="<?php echo $this->urlEscape($_item->getUrl()) ?>">
<?php echo $_item->getLabel() ?> <?php else: echo '>' . $_item->getLabel() ?> <?php endif; ?> (<?php echo $_item->getCount() ?>) </option>
<?php endforeach; ?> 
</select>
Palanikumar
  • 1,706
  • 5
  • 28
  • 51
  • Ok, it looks like there is a problem in Safari and IE. I get the drop down with the filter name repeated again and again. Like so: (For the price filter) - Choose Price, $0.00 - $49.99, Choose Price, $50.00 - $99.99, Choose Price etc. Clicking on any of the repeated 'Choose Price'values gives a 404 error. The error is only seen on Safari and IE. In IE, I can't actually select the 'Choose Price' value, but in Safari, I can, and this leads me to a 404 page. Any idea why this is happening? – GKRP Sep 14 '12 at 10:25
  • Thanks! Works well on all browsers. – GKRP Sep 19 '12 at 06:39