Question

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>

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top