Open category filters by default in Magento 2
-
28-09-2020 - |
Pergunta
Is it possible to open category filters in the left pane by default in Magento 2 Luma theme.
Solução
Just copy
vendor\magento\theme-frontend-luma\Magento_LayeredNavigation\templates\layer\view.phtml
into
app\design\frontend\<your_company>\<your_theme>\Magento_LayeredNavigation\templates\layer\
and change the 'data-mage-init' attribute as follow:
<?php foreach ($block->getFilters() as $filter): ?>
<?php if ($filter->getItemsCount()): ?>
<?php if (!$wrapOptions): ?>
<?php $collapsibleRange = implode(' ', range(0, $filter->getItemsCount())); ?>
<strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?php /* @escapeNotVerified */ echo __('Shopping Options') ?></strong>
<div class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": "<?php echo $collapsibleRange ?>", "multipleCollapsible": true}}'>
<?php $wrapOptions = true; endif; ?>
<div data-role="collapsible" class="filter-options-item">
<div data-role="title" class="filter-options-title"><?php /* @escapeNotVerified */ echo __($filter->getName()) ?></div>
<div data-role="content" class="filter-options-content"><?php /* @escapeNotVerified */ echo $block->getChildBlock('renderer')->render($filter); ?></div>
</div>
<?php endif; ?>
<?php endforeach; ?>
Outras dicas
I did not test it but I think if you change line 12
to true
it should work.
I don't know what the proper way to override js files in Magento 2 is yet. So you should look that up to do it the Magento way.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange