Magento: create a menu or list of all attributes and link to their filter results

This snippet can be placed in a phtml file which can be loaded into a Magento block, or straight into a menu template file. Should work for all types of attributes, even multi select and dropdown.

1. Creates a regular UL list from a certain attribute.
2. All options get a link to Catalogsearch/Advanced/Result with filter by attribute 3. Option value = the id and Option label = the text output
4. Javascript then sorts the list after the document is ready
5. Added toUpperCase so brands like iApple will be sorted correctly as well. List output labels are unaffected...
6. Added jQuery compatibility

<ul class="sorteeropmerk">
<?php
 $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'brand');
if ($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
foreach ($options as $option)

{
    echo '<li id="'.$option['label'].'" style="list-style:none"><a href="'.Mage::getUrl('catalogsearch/advanced/result').'?brand%5B%5D='.$option['value'].'">'.$option['label'].'</a></li>';
}
} ?>  
 
 </ul>
 <?php /* Javascript for sorting the brand menu alphabetically. Convert to case insensitive (all uppercase) IDs */  ?>
<script type="text/javascript">
jQuery(document).ready(function() {
$j(".sorteeropmerk li").sort(asc_sort).appendTo('.sorteeropmerk');
 //$("#debug").text("Output:");

// accending sort
function asc_sort(a, b){
        return ($j(b).text().toUpperCase()) < ($j(a).text().toUpperCase()) ? 1 : -1;    
    }

      });

</script>  

Hebt u meer vragen? Een aanvraag indienen

Opmerkingen

Mogelijk gemaakt door Zendesk