I'm using this code getting products. And also using some addAttributeToFilter method for filter.

$collection = Mage::getResourceModel('reports/product_collection')
    ->setOrder('created_at', 'desc')

Also I'm using $collection->count() code to get products count.

I'm trying to write my own pagination. (My products page is really complicated.)

Then I use this code setPage($pageNumber, $productsPerPage) to paginate.

But if I'm gonna paginate $collection->count() function return $productsPerPage number.

For example:

setPage(1, 6) // 6 product per page
$collection->count() // return 6 (but I have 16 products!)

If I use only $collection->count() code, it return 16!

What I'm missing?

I hope you guys understand me.


$collection->count() loads the collection and returns the number of products matching the select associated to the collection.
I think you are looking for $collection->getSize(). This will get you the total number of products matching the select, but ignores the limit.
Also getSize does not load the collection, so it's faster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.