Magento 2 Custom Layered Navigation – Implementation Guide

filterlayered-navigationmagento-2.1magento2PHP

enter image description here

Is it possible to create new custom layered navigation on left sidebar?
I want to display custom store and after clicking on store I would like to display
products on right side column .

Best Answer

Yes, it is possible to add any custom filter at categories pages. For this you need to craete a layout file inside your Module : app/code/MODULE_NAMESPACE/MODULE_NAME/view/frontend/layout/catalog_category_view.xml

<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <body>        
     <referenceContainer name="sidebar.additional">
   <block class="MODULE_NAMESPACE\MODULE_NAME\Block\YOUR_BLOCKNAME" name="MODULE_NAME.BLOCK" after ="-" template="MODULENAMESPACE_MODULENAME::YOURPHTMLFILE.phtml"/>
        </referenceContainer>
    </body>
</page>

Now create phtml file inside app/code/MODULE_NAMESPACE/MODULE_NAME/view/frontend/templates/YOURPHTMLFILE.phtml and Block file app/code/MODULE_NAMESPACE/MODULE_NAME/Block/YOUR_BLOCKNAME.php inside with your custom code.

For showing your custom collection rewrite Block Magento\Catalog\Block\Product\ListProduct this can be done as below: app/code/MODULE_NAMESPACE/MODULE_NAME/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
 <preference for="Magento\Catalog\Block\Product\ListProduct" type="MODULE_NAMESPACE\MODULE_NAME\Product\ListProduct" />
</config>



namespace MODULE_NAMESPACE\MODULE_NAME\Block\Product;
class ListProduct extends Magento\Catalog\Block\Product\ListProduct
{
  protected function _getProductCollection()
    {

        /*
      *  customize the default code
      */
    }

}
Related Topic