Magento2 Layered Navigation – How to Activate All Filters

layered-navigationmagento2

By default in Luma theme all the filters come in closed state and to make active all the filters in layered navigation I have tried this solution Open category filters by default in Magento 2 and hopefully got succeed in same.

But Now I see some strange behavior, Like few of filters are active by default and few are in closed state. On different categories it behave differently.

anyone with same problem kindly tell the solution if have any

Best Answer

My problem solved by placing altering some code lines and running few commands

In /app/design/frontend/packagename/themename/Magento_LayeredNavigation/templates/layer/view.phtml

1 ) Added the following line inside the foreach loop (foreach ($block->getFilters() as $filter) ):

<?php $range = implode(' ', range(0, $filter->getItemsCount())); ?>
  1. modify the div with class filter-options inside this loop, change active to as per below:

    div class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": "", "multipleCollapsible": true}}'>

reference: https://www.magevision.com/blog/post/open-category-filters-by-default-magento-2/

After all this I run few commands may be it was not working because cache enable or some other problem but after running these commands , it worked great

php bin/magento cache:clean

php bin/magento cache:flush

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy 
Related Topic