I have customized(override) product list collection getProductCollection and filtered collection as required.

public function getProductCollection()
        if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
            $collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
        } else {
            $collection = $this->collectionProvider->getCollection($this->getCurrentCategory());
            $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;

        /* custom filter conditions */
        $productUniqueIds = array(10,11,12,13);
        $collection->addAttributeToFilter('entity_id',array('in' => $productUniqueIds));
        /* custom filter conditions end here */

        return $collection;

Based on above products conditions, My result for listing page will be fine but layered navigation result is not proper, displays wrong filter attributes.

I am facing an issue in the layered navigation product count after applying filters on product collection. All counts are wrong. What I guess is I need to apply custom filters on layered navigation's collection as well, but I am not able to find it so far.

I have debugged and reached till _createItem function in vendor/magento/module-catalog/Model/Layer/Filter/AbstractFilter.php file. Product counts are coming from there, but I couldn't find from where exactly product collection gets returned.

Please share your ideas if you have. Any help would be appreciated. Thanks


This is a Magento Bug, You can see here : https://github.com/magento/magento2/issues/7730

You can take a pull changes from here : https://github.com/magento/magento2/pull/10246/files

Apply changes and check your count issue, Hope it might be useful for you.

| improve this answer | |

Please have a look on classs


On this plugin class at metod afterFilter, Magento add query search by below code


This comment this code and see what happen.

| improve this answer | |
  • Hello @AmitBera, It looks like collection doesn't filter from this function cause for debug I just added exit(); on top of function but page still works and nothing changed. – Sarvesh Ahuja Jun 18 '18 at 7:28

Please try to override getProductCollection() of this class


Set you custom collection here and then check.

| improve this answer | |
  • We have already overide getProductCollection() function – Rakesh Jesadiya Jun 18 '18 at 11:12
  • @Rakesh Jesadiya You have to override collection of product. Need to try collection of Layer. – Dharmendra Jadav Jun 18 '18 at 11:13

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.