I am trying to remove configurable products from product collection, as a result products are being filtered correctly but pagination is not working as expected and showing wrong count.

For example there are 30 products to be listed out of them there are 20 simple and 10 configurable. After making this change I am able to see only simple products on the listing page but sill count shows as 30 which should be 20.

Below is the change I have made in Magento\Catalog\Model\Layer using preference and plugin both but pagination is not working as expected. Below is my logic in the class mentioned:

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;

        $collection->addAttributeToFilter('type_id', ['neq'=>"configurable"]);
        return $collection;

I am using version 2.4.1-p1. Please let me know how I can manage this.

  • Can you please update question with what issue exactly you are facing with pagination. Commented Mar 26, 2021 at 10:41
  • @RahulBarot I have updated the question
    Commented Mar 30, 2021 at 4:35

1 Answer 1


I suggest you change the visibility of the products to either Search if you still want them to be shown in the search results page OR check this thread "Not Visible Individually" products disaply on Frontend in Magento2.4 where I detailed some workarounds to exclude products from listing, but still have them available at direct access by its URL.

  • it can be done via configuration, but I need to hide it on listing page programatically where I am facing issues with pagination count.
    Commented Mar 26, 2021 at 10:25
  • you will have to intervene in the place where the query is performed before it reaches Elasticsearch. any of the navigation or search features go through ES, the item IDs are returned from ES and the count you see and the LN options are related to that.
    – Diana
    Commented Mar 26, 2021 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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