Magento – Layered attribute navigation hiding when all active

cataloglayered-navigationmagento-1.9PHP

I'm having an issue with my Magento code which is used to modify the layout of the left layered navigation. I'm looking to have all items visible in the navigation even if they are currently active, however; when they are all active, the menu disappears. Did I incorrectly set it up or is there a simple mistake I have made?

1 Chosen Attribute: 2 Chosen Attributes:

Here is my code:

State.phtml

<?php
/**
 * Category layered navigation state
 *
 * @see Mage_Catalog_Block_Layer_State
 */
?>
<?php
$_filters = $this->getActiveFilters();
$_renderers = $this->getParentBlock()->getChild('state_renderers')->getSortedChildren();
$appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
?>
<?php if(!empty($_filters)): ?>
<div class="currently">
    <ol>
    <?php foreach ($_filters as $_filter): ?>
        <?php
        $_rendered = false;
        foreach ($_renderers as $_rendererName):
            $_renderer = $this->getParentBlock()->getChild('state_renderers')->getChild($_rendererName);
            if (method_exists($_renderer, 'shouldRender') && $_renderer->shouldRender($_filter)):
                $_renderer->setFilter($_filter);
                echo $_renderer->toHtml();
                $_rendered = true;
                break;
            endif;
        endforeach;
    endforeach; ?>
    </ol>
</div>
<?php endif; ?>

Filter.phtml

<?php
/**
 * Template for filter items block
 *
 * @see Mage_Catalog_Block_Layer_Filter
 */
$count = 0;
?>
<?php foreach ($this->getItems() as $_item):
    $count++;
    ?>
        <?php if ($_item->getCount() > 0): ?>
        <?
        $_filters = $this->getActiveFilters();
        ?>
        <div class="panel-group" id="accordion<? echo $count ?>" role="tablist" aria-multiselectable="true">
            <div class="panel panel-default">
                <div class="panel-heading" role="tab" id="heading<? echo $count ?>">
                    <h4 class="panel-title">
                        <a role="button" data-toggle="collapse" data-parent="#accordion<? echo $count ?>" href="#collapse<? echo $count ?>" aria-expanded="true" aria-controls="collapse<? $count ?>">
                            <dt><?php echo $this->__($_item->getName()) ?></dt>
                        </a>
                    </h4>
                </div>
                <div id="collapse<? echo $count ?>" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="heading<? echo $count ?>">
                    <div class="panel-body">
                        <dd>
                            <input type="checkbox" onclick="window.location.href='<?php echo $this->urlEscape($_item->getUrl()) ?>'"/>
                            <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>">
                                <?php echo $_item->getLabel() ?>
                            </a>
                        </dd>
                    </div>
                </div>
            </div>
        </div>
        <?php else: ?>
        <?php endif; ?>
<?php endforeach ?>
<?
$_appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
foreach ($_appliedFilters as $_item) {
    ?>
    <div class="panel-group" id="accordion<? echo $count ?>" role="tablist" aria-multiselectable="true">
        <div class="panel panel-default">
            <div class="panel-heading" role="tab" id="heading<? echo $count ?>">
                <h4 class="panel-title">
                    <a role="button" data-toggle="collapse" data-parent="#accordion<? echo $count ?>" href="#collapse<? echo $count ?>" aria-expanded="true" aria-controls="collapse<? $count ?>">
                        <dt><?php echo $this->__($_item->getName()) ?></dt>
                    </a>
                </h4>
            </div>
            <div id="collapse<? echo $count ?>" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="heading<? echo $count ?>">
                <div class="panel-body">
                    <dd>
                        <input type="checkbox" checked="true" onclick="window.location.href='<?php echo $this->urlEscape($_item->getRemoveUrl()) ?>'"/>
                        <a href="<?php echo $this->urlEscape($_item->getRemoveUrl()) ?>">
                            <?php echo $_item->getLabel() ?>
                        </a>
                    </dd>
                </div>
            </div>
        </div>
    </div>
<?php
}
?>

View.phtml

    <?php if($this->canShowBlock()): ?>
    <div class="block block-layered-nav">
        <div class="block-title">
            <h3>Refine By:</h3>
        </div>
        <div class="block-content refinements">
            <?php echo $this->getStateHtml(); ?>

            <?php if($this->canShowOptions()): ?>
                <dl id="narrow-by-list">
                    <dd>
                        <section id="nav-sidebox">
                            <?php
                            $_filters = $this->getFilters();
                            $_appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
                            $count = 0;
                            ?>
                            <?php foreach ($_filters as $_filter): ?>
                                <?php if($_filter->getItemsCount()):  ?>
                                    <?php echo $_filter->getHtml() ?>
                                <?php endif; ?>
                                <? $count = $count + 1; ?>
                            <?php endforeach; ?>
                            <?
                            if ($count == 0){
                                foreach ($_appliedFilters as $_filter): ?>
                                <?php if($_filter->getItemsCount()):  ?>
                                    <?php echo $_filter->getHtml() ?>
                                <?php endif; ?>
                                <? $count = $count + 1; ?>
                                <? endforeach; ?> <?
                            }
                            ?>
                        </section>
                    </dd>
                </dl>
                <script type="text/javascript">decorateDataList('narrow-by-list')</script>
            <?php endif; ?>
        </div>
    </div>
<?php endif; ?>

Best Answer

See As per Magento Standard How the Layered Navigation will be display.

  1. Layered Navigation will display Based on the Product listing.
  2. Layered Navigation contain the Filterable option which the generally the product Attributes. So that will be display in layered navigation.
  3. General logic Layered Navigation is Depended on the Product Listing.

In sort you can not display only Layered Navigation with your Products.