diff --git a/.all-contributorsrc b/.all-contributorsrc index 4ad1af49e5c..48409ae5488 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -919,6 +919,15 @@ "contributions": [ "code" ] + }, + { + "login": "dbachmann", + "name": "Daniel Bachmann", + "avatar_url": "https://avatars1.githubusercontent.com/u/1921769?v=4", + "profile": "https://github.com/dbachmann", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7 diff --git a/lib/Varien/Data/Collection/Db.php b/lib/Varien/Data/Collection/Db.php index a60fa212826..15490075c78 100644 --- a/lib/Varien/Data/Collection/Db.php +++ b/lib/Varien/Data/Collection/Db.php @@ -242,8 +242,17 @@ public function getSelectCountSql() $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); $countSelect->reset(Zend_Db_Select::COLUMNS); - $countSelect->columns('COUNT(*)'); - + if (count($this->getSelect()->getPart(Zend_Db_Select::GROUP)) > 0) { + $countSelect->reset(Zend_Db_Select::GROUP); + $countSelect->distinct(true); + $group = $this->getSelect()->getPart(Zend_Db_Select::GROUP); + $group = array_map(function($token) { + return $this->getSelect()->getAdapter()->quoteIdentifier($token, true); + }, $group); + $countSelect->columns("COUNT(DISTINCT " . implode(", ", $group) . ")"); + } else { + $countSelect->columns('COUNT(*)'); + } return $countSelect; }