How to apply custom conditions for product collection in Magento 2?

In Magento 2, There are some situations where you need to set custom conditions for layered(filter) navigation. In Magento 2, All product collection comes from Catalog Module at Layer.php file from vendor/magento/module-catalog/Model/Layer.php.

13 Replies to “How to apply custom conditions for product collection in Magento 2?”

  1. It seems like this is not working in Magento 2.3.0. If possible, may you please update the check and update the blog with the required changes.

  2. Hi,
    How to add custom condition before \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory Factory class create.
    I need to add a custom condition to Product Collection. Can you please help me?

  3. It seems like this is not working in Magento 2.3.0. If possible, may you please update the check and update the blog with the required changes.

  4. Hi,
    How to add custom condition before MagentoCatalogModelResourceModelProductCollectionFactory Factory class create.
    I need to add a custom condition to Product Collection. Can you please help me?

  5. Hi,
    I have apply custom condition in product listing with Elastic search extension of Amasty.
    It is working with results but filter count not getting proper any solution with Elastic search?

  6. I have upgraded magento 2.3.2 and i am getting error on search page.

    Fatal error: Uncaught Error: Cannot instantiate interface MagentoElasticsearchModelAdapterFieldMapperProductFieldProviderFieldNameResolverInterface in /vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:116 Stack trace: #0/vendor/magento/framework/ObjectManager/Factory/Compiled.php(108): MagentoFrameworkObjectManagerFactoryAbstractFactory->createObject(‘Magento\Elastic…’, Array) #1 /vendor/magento/framework/ObjectManager/Factory/Compiled.php(150): MagentoFrameworkObjectManagerFactoryCompiled->create(‘Magento\Elastic…’)

Leave a Reply