Try the Demo

Magento Forum

   
Page 10 of 10
Here is code to control layered navigation
 
chrismmmmm
Jr. Member
 
Total Posts:  6
Joined:  2011-01-11
 

hello - thanks for this snippet! - but for the life of me i cannot get my manufacturer attribute to show as a dropdown??? Price and category is working, i have set the threshold to 0, added case ‘manufacturer’: to the list of attribute names… but nothing seems to work -
- the site im trying to apply it too is a multisite
- we are using a shop by brands extension which uses the manufacturers attribute to create a brand listing

is there a setting within the attribute that could be blocking it from displaying as a dropdown?

thanks so much for any help! - chris

 
Magento Community Magento Community
Magento Community
Magento Community
 
overnightgrafix
Jr. Member
 
Avatar
Total Posts:  22
Joined:  2008-12-13
 

switch ($attributeName) {

case ‘Shoe Size’:
case ‘Price’:
case ‘Manufacturer’:
case ‘Overthreshold’:
_displayDropdown($this,$displayitemcount);
break;

fi you need more help visit us at http://www.overnightgrafix.com or email at

 
Magento Community Magento Community
Magento Community
Magento Community
 
Langus
Jr. Member
 
Total Posts:  15
Joined:  2009-11-08
 

Not working in 1.7

 
Magento Community Magento Community
Magento Community
Magento Community
 
teddyted
Jr. Member
 
Total Posts:  2
Joined:  2009-01-05
 
Tweakmag - 03 April 2008 04:47 PM

Hi there,
it seems a few people want to control the way layered navigation works, here is some code that will let you:
1. Define any attributes that you want to be displayed as a dropdown list
2. Set a threshold limit for the attributes, so that if this threshold is met, then automatically display as a dropdown list

This code needs to go into “app/design/frontend/default/[YOURTHEME]/template/catalog/layer/filter.phtml

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * @category   design_default
 * @package    Mage
 * @copyright  Copyright (c) 2004-2007 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * 
 */

/**
 * Template for filter items block
 * Coded by Adam Martin (www.tweakmag.com)
 * 
 * 
 * @see Mage_Catalog_Block_Layer_Filter
 */
?>

<?php
    
//control the way that the layered navigation attributes present themselves
    //either dropdown list or default methd (ordered list)
    
$attributeName $this->getName();
    
$itemcountthreshold 2// you can change this
    
$itemcount $this->getItemsCount();
    
$displayitemcount false//set to true/false to display item count in brackets
    
    
    
if($itemcount $itemcountthreshold){
        $attributeName 
"Overthreshold";
    
}
    
    
if(!function_exists("_displayOrderedlist")){
        
function _displayOrderedlist($atts,$displayitemcount){
            
echo '<ol>';
            foreach(
$atts->getItems() as $_item){
                
echo '<li><a href="'.$_item->getUrl().'">'.$_item->getLabel().'</a>';
                if(
$displayitemcount){
                    
echo ' ('.$_item->getCount().')';
                
}
                
echo '</li>';
            
}
            
echo '</ol>';
        
}
    }
    
if(!function_exists("_displayDropdown")){
        
function _displayDropdown($atts,$displayitemcount){
            
echo '<select id="layered-select" class="select" name="layered-select" onchange="if (this.selectedIndex > 0) location.href=this[this.selectedIndex].value;">';
            echo 
'<option selected="selected">Please select</option>';
            foreach (
$atts->getItems() as $_item){
                
echo '<option value="'.$_item->getUrl().'">';
                echo 
$_item->getLabel();
                if(
$displayitemcount){
                    
echo ' ('.$_item->getCount().')';
                
}
                
echo '</option>';
            
}
            
echo '</select>';
        
}
    }
    
    
switch ($attributeName{
        
case 'Shoe Size':
        case 
'Overthreshold':
            
_displayDropdown($this,$displayitemcount);
            break;
    
        default:
            
_displayOrderedlist($this,$displayitemcount);
            break;
    
}    
    
?>

You will see that I have added case ‘Shoe Size’ - by doing this anytime the Shoe Size attribute is displayed it will be displayed using a dropdown. For example you could add:

case 'Price':
to make price always display as a dropdown.

Cheers
Adam

Thank you!  I think this is the best way to customize layered navigation!

 
Magento Community Magento Community
Magento Community
Magento Community
 
GoodLook
Jr. Member
 
Total Posts:  2
Joined:  2010-04-29
 
Langus - 31 January 2013 08:22 AM

Not working in 1.7

is there already a update for version 1.7?

 
Magento Community Magento Community
Magento Community
Magento Community
 
ChaseWalker
Jr. Member
 
Total Posts:  17
Joined:  2009-06-09
 

Thanks so much for posting this snippet - works fabulously!

 
Magento Community Magento Community
Magento Community
Magento Community
 
miky4u2
Jr. Member
 
Total Posts:  1
Joined:  2012-12-11
 

This works really good for me as i needed only my long Manufacturer list to be a dropdown… When I use it in conjunction with the Vinagento Vpager extension (part of my existing theme) ( http://www.magentocommerce.com/magento-connect/catalogsearch/result/?q=vinagento&pl;=0 )
, the dropdown menus do not take advantage of the Ajax provided via the extension.  Maybe a tiny modification would allow the dropdown menus to use Ajax.

Nevertheless , your code as is , really made my day.

Miky

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 10 of 10