Sunday 21 August 2016

Display image column in manage category grid magento admin


Display image column in manage category grid magento admin


Here i will show you how to create image column in admin mangage category grid magento.

First open app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Product.php file.

You can copy this file in your local folder so that magento core functionality will not be override.

Put the below code in _prepareColumns() function to create image column in grid.

    $this->addColumn('image', array(
        'header' => Mage::helper('catalog')->__('Image'),
        'align' => 'left',
        'index' => 'image',
        'width'     => '100',
        'renderer'  => 'adminhtml/Catalog_Category_Grid_Render_Image',
    ));

You can check in code we have created renderer to fetch product image. Now as per renderer create the Grid folder then Render folder and then Image.php file in app/code/core/Mage/Adminhtml/Block/Catalog/Category/ folder

Copy and paste the below code in Image.php file

class Mage_Adminhtml_Block_Catalog_Category_Grid_Render_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row)
{
$products = Mage::getModel('catalog/product')->load($row->getEntityId());
try{
  $imgSrc = Mage::helper('catalog/image')->init($products, 'small_image')->resize(100);
}
catch(Exception $e) {
  $imgSrc = Mage::getDesign()->getSkinUrl('images/catalog/product/placeholder/image.jpg',array('_area'=>'frontend'));
}
return '<img src="'.$imgSrc.'" alt="'.$strBannerTitle.'" title="'.$strBannerTitle.'" width="100px">';
    }
}

Now you can check in admin panel image shows in image column like below:

1 comment:

Unknown said...

Thanks for the best blog.it was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!
magento development company in bangalore