1

short :

Attribute have many dropdown values - v1,v2,v3,v4

IF all Products are assigned to value "v1" of an attribute , means no products are assigned to "v2,v3.v4" than that Attribute label should not visible under Layered Navigation....

Long :

we wanted to hide one attribute value in layered navigation.

many attribute codes have same attribute value.

ex: "attribute codes "a1", "a2", "a3", "a4" have attribute value "v1"

we are using following code to hide the attribute value "v1" in layered navigation.

but Attribute Label is still displaying in layered navigation.

if for attribute code : "a1" , attribute label is "L1" , values are "v1", "v2","v3"

if all products are assigned to "v1", than along with "v1" , I want to hide "L1" in layered navigation.

enter image description here

<?php if($this->canShowBlock()): ?>
<div class="block block-layered-nav">
<div class="block-title">
        <strong><span><?php echo $this->__('Browse') ?></span></strong>
    </div>
    <div class="block-content">
        <?php echo $this->getStateHtml() ?>
        <?php if ($this->getLayer()->getState()->getFilters()): ?>
            <div class="actions"><a href="<?php echo $this->getClearUrl() ?>"><?php echo $this->__('Clear All') ?></a></div>
        <?php endif; ?>
        <?php if($this->canShowOptions()): ?>
            <dl id="narrow-by-list">
                <?php $_filters = $this->getFilters() ?>
                <?php foreach ($_filters as $_filter): ?>
                <?php if($_filter->getItemsCount()): ?>      

                <!-- L1 -->

            <?php if($this->__($_filter->getName())=='L1'&& $_filter->getItemsCount()<=1) continue;?>

                <!-- L1 -->

                    <dt><?php echo $this->__($_filter->getName()) ?></dt>
                    <dd><?php echo $_filter->getHtml() ?></dd>
                <?php endif; ?>
                <?php endforeach; ?>
            </dl>
            <script type="text/javascript">decorateDataList('narrow-by-list')</script>
            <script type="text/javascript">
                jQuery(function($){
                    $(".block-layered-nav dt").click(function(){
                        if($(this).next("dd").css("display") == "none"){
                            $(this).next("dd").slideDown(1000);
                            $(this).removeClass("closed");
                        } else {
                            $(this).next("dd").slideUp(1000);
                            $(this).addClass("closed");
                        }
                    });
                });
            </script>

        <?php endif; ?>
    </div>
</div>
<?php endif; ?>

when we use following code , it hided only L1 attribute label , but we have to hide multiple attribute labels like this.

<?php if($this->__($_filter->getName())=='L1'&& $_filter->getItemsCount()<=1) continue;?>
  • "IF all Products are assigned to value "v1" of an attribute , means no products are assigned to "v2,v3.v4" than that Attribute label should not visible under Layered Navigation...." Magento does this by default with the proper setup. You might have to index(check all cache as well), but this is a basic function of all Navigation tools. So I'm a little confused on what the issue is. Why do you have code to 'Hide' why not just disable in admin? – Anthony Cicchelli Apr 3 '16 at 19:02
  • in some links, attribute having one value v1, in some other links the attribute having 2 or 3 values [v1, v2, v3] , if i disable the attribute from backend, than that attribute will not visible in other links also. please let me know if you need more clarifications. – Baby in Magento Apr 3 '16 at 19:08
  • Itshould be pretty basic. Admin > Catalog > Attributes > Manage attributes and set "Filterable (with results)" for attribute property "Use in the layered navigation." If this is setup advanced navigation should do the work for the different 'links/categories' If the value is empty for the specific category than it should be hidden automatically. Of course index much be done each time there is a change. – Anthony Cicchelli Apr 3 '16 at 19:20
  • for the attribute we set : Filterable (with results) . here the attribute label value has value v1, but we hide the attribute value "v1" in layered navigation. so only attribute label is displaying under layered navigation. your solution will work if we have empty values for attribute. but in our case we have values for that attribute. – Baby in Magento Apr 3 '16 at 19:32
  • Yes, but you should have logic built around this. Categories are perfect for this as if the category doesn't contain the info it will not be visible, if it does, it will be visible. This is what most stores do. – Anthony Cicchelli Apr 3 '16 at 19:51
2
+50

go to template/catalog/layer/filter.phtml and change <?php if ($_item->getCount() > 0): ?> this will not show the single product values..

<ol>
<?php foreach ($this->getItems() as $_item): ?>
    <li>
        <?php if ($_item->getCount() > 1): ?>
        <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>
        <?php else: echo $_item->getLabel() ?>
        <?php endif; ?>
        <?php if ($this->shouldDisplayProductCount()): ?>
        (<?php echo $_item->getCount() ?>)
        <?php endif; ?>
    </li>
<?php endforeach ?>
</ol>

for not showing the label

<?php if($this->__($_filter->getName())=='L1' || $this->__($_filter->getName())=='L2' && $_filter->getItemsCount()) continue;?>

            <!-- L1 -->

                <dt><?php echo $this->__($_filter->getName()) ?></dt>
                <dd><?php echo $_filter->getHtml() ?></dd>
            <?php endif; ?>
  • it didt worked for me , you can check here with "L1" & "L2" under layered navigation. – Baby in Magento Apr 4 '16 at 7:06
  • try this condition hope work for you.. – Qaisar Satti Apr 4 '16 at 7:15
  • Thanks a lot, This worked fine, but only problem is we have some 100 attributes like this. manually we have to add all attributes lablels in code. is there any other way? – Baby in Magento Apr 4 '16 at 7:24
  • they don't have any item? or any else condition? – Qaisar Satti Apr 4 '16 at 7:28
  • those labels have items, but only one item , that is "v1" , we hide the "v1" . i am not getting about else condition. – Baby in Magento Apr 4 '16 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.