1

I have used below code for Grid Products Image in shopping cart tab, Its showing same image in all products, Please help , Kindly check attached snap-shot for more detail.


$this->addColumn('Image', array(
        'header'=> Mage::helper('catalog')->__('Image'),
        'type'  => 'image',
        'width' => '100px',
        'index' => 'image',
        'frame_callback' => array($this, 'callback_image')

    ));

public function callback_image()
{

          $_productCollection = $this->getCollection();
    foreach ($_productCollection as $_product){
        $product_id = $_product->getProductId();
    }
    if(isset($product_id)){
        $product = Mage::getModel('catalog/product')->load($product_id);
        $productMediaConfig = Mage::getModel('catalog/product_media_config');
        $smallImageUrl = $productMediaConfig->getMediaUrl($product->getSmallImage());
        $width = 70;
        $height = 70;
        return "<img src='".$smallImageUrl."' width=".$width." height=".$height."/>";
    }
}

enter image description here

1
  • You need to first verify that, you get proper $product_id in your function. I think It return same Id every call. Sep 17, 2016 at 4:50

1 Answer 1

1

Try this

$this->addColumn('Image', array(
    'header'=> Mage::helper('catalog')->__('Image'),
    'type'  => 'image',
    'width' => '100px',
    'index' => 'image',
    'renderer'  => 'Mage_Adminhtml_Block_Sales_Order_Renderer_Red',

));

And make a class file (You can make your own class file in your module and use that path)

class Mage_Adminhtml_Block_Sales_Order_Renderer_Red extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
      public function render(Varien_Object $row)
      {
    $imageUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product/'
    $productId =  $row->getData($this->getColumn()->getIndex());
    $product = Mage::getModel('catalog/product')->load($productId);
    $smallImageUrl = $imageUrl.$product->getSmallImage();
    $width = 70;
    $height = 70;
    return "<img src='".$smallImageUrl."' width=".$width." height=".$height."/>";


      }
}
3
  • But, What's the Wrong with my code, can u please check Sep 17, 2016 at 15:04
  • Fatal error: Call to a member function getMediaUrl() on null in /home/mysticex/public_html/testinter/app/code/core/Mage/Adminhtml/Block/Sales/Order/Renderer/Red.php on line 8 i am getting this Error Sep 17, 2016 at 15:12
  • Check updated answer Sep 18, 2016 at 12:56

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.