I have an array object that is an output of a magento fetchall from DB and i want this to be converted to an object of a Collections class so that i can implement pagination
If you have an array of ids $product_ids
, you can use:
$collection = Mage::getModel('catalog/product')->getCollection()
->addIdFilter($product_ids);
Also, populating a collection can be done with the addItem
method.
Magento hasn't a built in conversor for that, but you can write you query using Collections, or load the Collection based on all ids from your array.
In order to convert an array to a collection object:
1> Create an instance of Varien_Db_Collection
$collection = new Varien_Data_Collection();
2> Create an instance of Varien_Object and set the array data
$rowObj = new Varien_Object();
$rowObj->setData($row);
3> Finally add the Varien_Object to Collection instance
$collection->addItem($rowObj);
4> Now $collection is a collection object.