From deb53ab20d1d350ebcba2c57620bd7f757cdbd99 Mon Sep 17 00:00:00 2001 From: Ryan Hewitt Date: Wed, 5 Jan 2022 23:46:56 +0000 Subject: [PATCH] Simplify/improve product list total results and pagination object functions (fix for #606) --- src/CommunityStore/Product/ProductList.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/CommunityStore/Product/ProductList.php b/src/CommunityStore/Product/ProductList.php index d4b7989ca..d01ac15b3 100644 --- a/src/CommunityStore/Product/ProductList.php +++ b/src/CommunityStore/Product/ProductList.php @@ -379,10 +379,7 @@ public function getResult($queryRow) protected function createPaginationObject() { $adapter = new DoctrineDbalAdapter($this->deliverQueryObject(), function ($query) { - $values = $query->execute()->fetchAll(); - $count = count($values); - - $query->resetQueryParts(['groupBy', 'orderBy', 'having', 'join', 'where', 'from'])->from('DUAL')->select($count . ' c '); + $query->resetQueryParts(['groupBy', 'orderBy'])->select('count(distinct p.pID)')->setMaxResults(1)->execute()->fetchColumn(); }); $pagination = new Pagination($this, $adapter); @@ -408,10 +405,7 @@ public function getPaginationAdapter() public function getTotalResults() { $query = $this->deliverQueryObject(); - $values = $query->execute()->fetchAll(); - $count = count($values); - - return $query->resetQueryParts(['groupBy', 'orderBy', 'having', 'join', 'where', 'from'])->from('DUAL')->select($count)->setMaxResults(1)->execute()->fetchColumn(); + return $query->resetQueryParts(['groupBy', 'orderBy'])->select('count(distinct p.pID)')->setMaxResults(1)->execute()->fetchColumn(); } public function getResultIDs()