Showing posts with label How to display image column in category page magento admin. Show all posts
Showing posts with label How to display image column in category page magento admin. Show all posts

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: