Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 10 of 10
Here is code to control layered navigation
 
chrismmmmm
Jr. Member
 
Total Posts:  7
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:  23
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:  3
Joined:  2009-01-05
 
Tweakmag - 03 April 2008 03: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 07:22 AM

Not working in 1.7

is there already a update for version 1.7?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jase Clamp
Jr. Member
 
Total Posts:  19
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:  2
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
 
henrycullen
Jr. Member
 
Avatar
Total Posts:  2
Joined:  2013-07-22
UK
 

It is rare when someone gives out some good useful and simple code for Magento
well done and thank you

working in Mage 1.8 although it is affecting Price as well as Manufacturer, but for now I\\m happy.

 
Magento Community Magento Community
Magento Community
Magento Community
 
denialdesign
Jr. Member
 
Total Posts:  9
Joined:  2012-02-12
 

Great piece of code by Tweakmag but I noticed that by default Magento displays all the options available in some cases even when no products match. I added a simple filter to remove the options where the product count is 0.

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){
                
if ($_item->getCount() > 0{
                
echo '<option value="'.$_item->getUrl().'">';
                echo 
$_item->getLabel();
                if(
$displayitemcount){
                    
echo ' ('.$_item->getCount().')';
                
}
                
echo '</option>';
                
}
            }
            
echo '</select>';
        
}
    }
 
Magento Community Magento Community
Magento Community
Magento Community
 
Andos2009
Jr. Member
 
Total Posts:  1
Joined:  2013-02-14
 

Hi, sorry to jump on the end of an old thread but I was just reading it through thinking this is quite close to the problem I am trying to solve.

The issue is that when you set a category to be either an anchor or not then the side menus are changed accordingly. If the category is an anchor then the side menu shows the product attribute filters. However, if it is not an anchor it shows the ‘Browse by’ category links.

I am trying to get both of these sections to show at the same time as the client requires. Is there an easy way to do this as I have had no luck so far?

Andrew

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