We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    To add custom conditions to product collection, you need to override build() function.  I hope you have a custom module with basic skeletons like registration.php and module.xml file,

    Path: app/code/Magemonkeys/FilterSearch/etc/frontend/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">
        <!-- Magento Catalog search module's IndexBuilder.php plugin file -->
        <type name="MagentoCatalogSearchModelSearchIndexBuilder">
            <plugin name="Magemonkeys_FilterSearch::custom_filterSearchr_conditions"
                    type="MagemonkeysFilterSearchPluginCatalogSearchModelSearchIndexBuilder" />
        </type>
    </config>

    Path: app/code/Magemonkeys/FilterSearch/Plugin/CatalogSearch/Model/Search/IndexBuilder.php

    <?php
    namespace MagemonkeysFilterSearchPluginCatalogSearchModelSearch;
    
    use MagentoFrameworkSearchRequestInterface;
    
    class IndexBuilder
    {
    
        public function __construct(
            MagentoStoreModelStoreManagerInterface $storeManager,
            MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory
        ) {
            $this->storeManager = $storeManager;
            $this->_productCollectionFactory = $productCollectionFactory;
        }
    
        public function aroundBuild(MagentoCatalogSearchModelSearchIndexBuilder $subject, callable $proceed, RequestInterface $request)
        {
            $select = $proceed($request);
            /* customization by magemonkeys */
            	$storeId = $this->storeManager->getStore()->getStoreId();
                $query = 'WHERE_CUSTOM_CONDITION';
                $select->where($query);
            /* customization by magemonkeys end here */
            return $select;
        }
    
    }

     

    field_5bfb909c5ccae

      Get a Free Quote