0

I was trying to Sort product listing with created_at and group by Name, that why i added

$this->_productCollection->addAttributeToSort('created_at', 'desc')
                ->getSelect()->group('name');;

before

return $this->_productCollection;

in function _getProductCollection()

//app/code/local/Mage/Catalog/Block/Product/list.php

sorting is working fine but pagination and item quantity showing wrong. enter image description here

It looks like only 1 products but i have much product here and i have not changed anything in toolbar page.

1 Answer 1

1

I don't know why you have the group() statement there. If you don't need it remove it.
In case you need it you have an other issue not related to sorting.
This is a general issue with Magento Collections. The getSize() method does not play well with GROUP BY.
Here is one of the solutions (most used one I think)

An other solution (a more elegant one in my opinion) can be extracted from the accepted answer to this question
The question is about adding the category names to the product grid, but it ends up with the same issue. getSize() returns 1.
The main idea with the second solution is to override the method getSelectCountSql of the collection you need (in your case the product collection) and let it behave like it usually does when you don't have a group by statement and change its behavior when group by is involved.

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.