0

I am using magento 2.4 version. I wanna user custom filter in product collection so I override getProductCollection() function in \Magento\Catalog\Model\Layer.php but it filters the product but not filter totalproducts count and layerednavigation. Anyone knows which file I have to refer to filter layerednavigation and count totalproducts in product listing page ? I am stuck I tried other solutions which is mentioned on google but not working. Please help

 /**
     * Retrieve current layer product collection
     *
     * @return \Magento\Catalog\Model\ResourceModel\Product\Collection
     */
    public function getProductCollection()
    {
        if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
            $collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
        } else {
            $collection = $this->collectionProvider->getCollection($this->getCurrentCategory());
            
            $this->prepareProductCollection($collection);
            $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
        }
        /* custom code */
        $collection->addAttributeToSelect('show_notify')
         $collection->addAttributeToFilter('show_notify',1);
        return $collection;
    } 

Your Answer

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

Browse other questions tagged or ask your own question.