I do have following code below for a Grid in Admin

protected function _prepareCollection()
    $pimage_collection = new Varien_Data_Collection();  
    $pimage_array = array();

    $product_collection = Mage::getModel('catalog/product')->getCollection();

    foreach($product_collection as $product) {

        $prod =  Mage::getModel('catalog/product')->load($product->getId());      

        foreach ($prod->getMediaGalleryImages() as $image) {
            $pimage_object = new Varien_Object();
            $pimage_array[] = $pimage_object->getData('id');


    return parent::_prepareCollection();

Now what I want there is to create a grid showing all the images of all products in my catalog.

It seems to work fine as it show all the images already and all the products.

But it breaks the pagination. How can i fix this?

1 Answer 1


Grid pagination is realized in Mage_Adminhtml_Block_Widget_Grid::_preparePage().

The default implementation expects the collection to be a database collection that's not loaded yet:

protected function _preparePage()
    $this->getCollection()->setPageSize((int) $this->getParam($this->getVarNameLimit(), $this->_defaultLimit));
    $this->getCollection()->setCurPage((int) $this->getParam($this->getVarNamePage(), $this->_defaultPage));

With your hand crafted collection, you have to override this method to slice the collection.

If you want to optimize, you could prepare the pagination directly in _prepareCollection() based on the "limit" and "page" parameters determined as above. But in your case, getMediaGalleryImages() will load all images anyway and does not provide means to paginate, so it would not help much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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