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

  • You need to first verify that, you get proper $product_id in your function. I think It return same Id every call. – Dhiren Vasoya Sep 17 '16 at 4:50
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."/>";


      }
}
  • But, What's the Wrong with my code, can u please check – Kunwar Sunil chauhan Sep 17 '16 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 – Kunwar Sunil chauhan Sep 17 '16 at 15:12
  • Check updated answer – Ashish Jagnani Sep 18 '16 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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