2

I want to update the Active filter position from left side to right side just above the product listing. Please guide me how can i do that.

Current Position: On left side

enter image description here

Required Position: I want to display on the right side

enter image description here

I tried using the layout xml files but it did not work for me. If you guys have an alternate solution please provide me. Your help would be appriciated.

Thanks.

2

1 Answer 1

1

Please add the below code in your custom module :

app/code/Vendor/Module/view/frontend/layout/catalog_catagory_view_type_layered.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <attribute name="class" value="page-with-filter"/>
        <referenceContainer name="sidebar.main">
            <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">
                    <arguments>
                        <argument name="product_layer_view_model" xsi:type="object">Magento\LayeredNavigation\ViewModel\Layer\Filter</argument>
                    </arguments>
                </block>
            </block>
        </referenceContainer>
        <move element="catalog.navigation.state" destination="content" before="category.products" />
    </body>
</page>

Then override the Navigation.php file and edit in the following function and then add the following in the navigation.php file Vendor/Module/Block/Navigation.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\LayeredNavigation\Block;

use Magento\Framework\View\Element\Template;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Catalog\Block\Product\ProductList\Toolbar;

/**
 * Catalog layered navigation view block
 *
 * @api
 * @since 100.0.2
 */
class Navigation extends \Magento\Framework\View\Element\Template
{
    public function getClearUrl()
    {
        
        return $this->getChildBlock('state') ?$this->getChildBlock('state')->getClearUrl():"";
    }
}
?>

Then create the di.xml file and override the Navigation.php file using the preference method Vendor/Module/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\LayeredNavigation\Block\Navigation" type="Vendor\Magento\Block\Navigation" />
</config>

Now, Add Magento_LayeredNavigation in the sequence tag of your module.xml file

<?xml version="1.0"?>
<!--/**
* Copyright © 2020 Grazitti . All rights reserved.
*/-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Vendor_Magento" setup_version="2.0.3">
        <sequence>
            <module name="Magento_LayeredNavigation"/>
        </sequence>
    </module>
</config>
2
  • I am facing this error, <a href="Error: Call to a member function getClearUrl() on bool in /var/www/html/opt-staging/vendor/magento/module-layered-navigation/Block/Navigation.php:136 could not override the Navigation.php file Commented Oct 11, 2023 at 11:59
  • @SunnyRahevar updated the answer you have to add the "Magento_LayeredNavigation" in the sequence tag in "module.xml" file. Please accept the answer if it works Commented Oct 12, 2023 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.