0

I have one module is set up and it has configuration about enable/disable the module. I have multiple stores too. I want the functionality to disable or hide price filter from category page if the module is enabled or not.

In my module, I have the function in helper which returns the value of module enabled or not. It would depend on store view.

As the price attribute has global scope, So we can not directly use this:

Catalog->Attributes ->Manage Attributes -> Price -> Use In Layered Navigation -> "No".

Now I want to disable the price filter from left/right navigation from the category page.

Is anyone have any an idea about it?

in Helper\Data.php I have content as below:

namespace Name\Module\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    const XML_CONFIG_ENABLE = "sectionid/groupid/fieldid";

    protected $scopeConfig;

    public function __construct(
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
    ) {
        $this->scopeConfig = $scopeConfig;      
    }

    public function getModuleStatus()
    {
        return  $this->scopeConfig->getValue(self::XML_CONFIG_ENABLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
    }

Thanks.

3
  • 1
    Can you update your module code so that I can write a answer based on your module? Atleast the helper class. Dec 24, 2018 at 9:33
  • in my module, I have system.xml file and Data.php it has a function which returns the value if the module enables then return 1 otherwise 0. Dec 24, 2018 at 9:41
  • Can you update the whole helper file? Dec 24, 2018 at 10:05

1 Answer 1

3

Add the below code to your 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\Catalog\Model\Layer\Category\FilterableAttributeList" type="Name\Module\Model\Layer\FilterableAttributeList" />
</config>

And create FilterableAttributeList.php under

app/code/Name/Module/Model/Layer/FilterableAttributeList.php

with following content:

<?php
namespace Name\Module\Model\Layer;

class FilterableAttributeList extends \Magento\Catalog\Model\Layer\Category\FilterableAttributeList
{
    protected $collectionFactory;
    protected $storeManager;
    protected $helper;
    public function __construct(
        \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $collectionFactory,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Name\Module\Helper $helper
    ) {
        $this->collectionFactory = $collectionFactory;
        $this->storeManager = $storeManager;
        $this->helper = $helper;
        parent::__construct($collectionFactory, $storeManager)
    }

    protected function _prepareAttributeCollection($collection)
    {
        $collection->addIsFilterableFilter();
        if($helper->getModuleStatus() == 1){
            $collection->removePriceFilter();
        }
        return $collection;
    }
}
2
  • Thanks you so much @Sukumar Gorai its working fine. Dec 24, 2018 at 12:58
  • Welcome. Happy Coding! Dec 24, 2018 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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