Magento 2 pager wrong count when using GROUP BY

Magento 2 pager wrong count when using GROUP BY

After Spent my lot of time, finally I have find solution for wrong count with groupby Issue and it’s work for me. So, I have share this solution with you all. I hope it’ll help you to.

For solution of wrong count with group you just need to follow 2 step which I listed below.

  1. Open Toolbar.php file from : magento_root/vendor/magento/module-catalog/Block/Product/ProductList/Toolbar.php 
    And Find ” public function getTotalNum() “


    return $this->getCollection()->getSize();

    to this

    return $this->getCollection()->count();
  2. Open Collection.php file from : magento_root/vendor/magento/module-catalog/Model/ResourceModel/Product/Collection.php 
    And Add following function at end of the class.
public function getLastPageNumber()
        $collectionSize = (int)$this->getAllIds();
        if (0 === $collectionSize) {
            return 1;
        } elseif ($this->_pageSize) {
            return ceil($collectionSize / $this->_pageSize);
        } else {
            return 1;

If this solution is working for you then I suggest you don’t direct change to core file just override class and block and add the solution on that.

I Hope this will help you. and incase if this solution is not working for you and you find another solution for that then I’ll request you all the guy’s please share to all.

Thank you ☺,
Mayank Zalavadia