Skip to content

Commit fd5796b

Browse files
authored
[BUGFIX] Count doesn't work with group by columns. This fix keeps the group by (#1404)
* [BUGFIX] Count doesn't work with group by columns. This fix keeps the group by. * [BUGFIX] - Fixed html structural error in pnepage checkout payments section. When using definition term and definition description this items should be located in a definition list. * [BUGFIX] - Fixed missing opening paragraph in email-template as mentioned in #1401 * [BUGFIX] Added fix to prevent sql injections as recommended by @colinmollenhour * Added @dbachmann as contributor * Revert "[BUGFIX] - Fixed missing opening paragraph in email-template as mentioned in #1401" This reverts commit 3e66cf9. * Revert "[BUGFIX] - Fixed html structural error in pnepage checkout payments section. When using definition term and definition description this items should be located in a definition list." This reverts commit 345ab99.
1 parent 18cb71a commit fd5796b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,15 @@
919919
"contributions": [
920920
"code"
921921
]
922+
},
923+
{
924+
"login": "dbachmann",
925+
"name": "Daniel Bachmann",
926+
"avatar_url": "https://avatars1.githubusercontent.com/u/1921769?v=4",
927+
"profile": "https://github.com/dbachmann",
928+
"contributions": [
929+
"code"
930+
]
922931
}
923932
],
924933
"contributorsPerLine": 7

lib/Varien/Data/Collection/Db.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,17 @@ public function getSelectCountSql()
242242
$countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
243243
$countSelect->reset(Zend_Db_Select::COLUMNS);
244244

245-
$countSelect->columns('COUNT(*)');
246-
245+
if (count($this->getSelect()->getPart(Zend_Db_Select::GROUP)) > 0) {
246+
$countSelect->reset(Zend_Db_Select::GROUP);
247+
$countSelect->distinct(true);
248+
$group = $this->getSelect()->getPart(Zend_Db_Select::GROUP);
249+
$group = array_map(function($token) {
250+
return $this->getSelect()->getAdapter()->quoteIdentifier($token, true);
251+
}, $group);
252+
$countSelect->columns("COUNT(DISTINCT " . implode(", ", $group) . ")");
253+
} else {
254+
$countSelect->columns('COUNT(*)');
255+
}
247256
return $countSelect;
248257
}
249258

0 commit comments

Comments
 (0)