I am trying to display Layered Navigation Block on custom page with custom product list.
For now i have custom controller, xml layout and template for product list.
<referenceContainer name="sidebar.main">
<!-- ??? -->
</referenceContainer>
Magento 2 general setting provides you with the option to configure layered navigation based on price navigation. In order to configure it, you need to go to Stores > Configuration > Catalog > Catalog > Layered Navigation.
For Apply custom condition before product collection loaded, you need to create a di. xml file for plugin definition and plugin PHP file for add your custom logic. Under the di. xml file, You need to add plugin definition to create plugin beforeLoad( ) method.
Collections in Magento are extremely useful, they allow you to retrieve objects such as products, categories, customers, etc. Retrieving these objects in a collection is a simple case of instantiating an instance of the object entity's factory class and using the model's 'getCollection' method, as follows.
The XML you need can be found in Magento/LayeredNavigation/view/frontend/layout/catalog_category_view_type_layered.xml
The snippet you'll need to add to your referenceContainer is:
<block class="Magento\LayeredNavigation\Block\Navigation\Category" name="catalog.leftnav" before="-" template="Magento_LayeredNavigation::layer/view.phtml">
<block class="Magento\LayeredNavigation\Block\Navigation\State" name="catalog.navigation.state" as="state" />
<block class="Magento\LayeredNavigation\Block\Navigation\FilterRenderer" name="catalog.navigation.renderer" as="renderer" template="Magento_LayeredNavigation::layer/filter.phtml"/>
</block>
I would suggest using a plugin to modify the render method of "Magento\LayeredNavigation\Block\Navigation\FilterRenderer" if you want to set a default filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With