The question that I tried to find out was how do we set a Limit on a Collection, the answers that I found on Google was only available for the Catalog with a setPage($pageNum, $pageSize). That didn't work on any other collections.
See the answer below.
Here is the alternative and maybe more readable way: $collection = Mage::getModel('...')->getCollection(); $collection->getSelect()->limit(20); This will call Zend Db limit. You can set offset as second parameter.
There are several ways to do this:
$collection = Mage::getModel('...') ->getCollection() ->setPageSize(20) ->setCurPage(1);
Will get first 20 records.
Here is the alternative and maybe more readable way:
$collection = Mage::getModel('...')->getCollection(); $collection->getSelect()->limit(20);
This will call Zend Db limit. You can set offset as second parameter.
The way to do was looking at the code in code/core/Mage/Catalog/Model/Resource/Category/Flat/Collection.php
at line 380 in Magento 1.7.2 on the function setPage($pageNum, $pageSize)
$collection = Mage::getModel('model') ->getCollection() ->setCurPage(2) // 2nd page ->setPageSize(10); // 10 elements per pages
I hope this will help someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With