Friday 14 June 2013

add image in custom module grid magento


create folder on given module path path
code\local\Package\Module\Block\Adminhtml\Module\Renderer

then create file in given folder Image.php

and put the code as suggested.



<?php
class Package_Module_Block_Adminhtml_Module_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{
   
    public function render(Varien_Object $row)
    {
        $html = '<img width="75" height="75" ';
        $html .= 'id="' . $this->getColumn()->getId() . '" ';
        $html .= 'src="' . Mage::getBaseUrl('media').$row->getData($this->getColumn()->getIndex()) . '"';
        $html .= 'class="grid-image ' . $this->getColumn()->getInlineCss() . '"/>';
      //  $html .= '<br/><p>'.$row->getData($this->getColumn()->getIndex()).'</p>';
        return $html;
    }
}
?>

save file
then go to grid file path is given bellow

app\code\local\Package\Module\Block\Adminhtml\Module\Grid.php

and  add new column in following ways



$this->addColumn('image', array(
'header'    => Mage::helper('module')->__('image'),
'align'     =>'left',
'index'     =>'image',
'renderer' =>'module/adminhtml_module_renderer_image'
));



Tuesday 4 June 2013

get associated product configrable product magento

$productId = 3;
$product = Mage::getModel('catalog/product')->load($productId);
$configrable = $product->getTypeInstance()->getUsedProducts();
foreach($configrable as $config){
                  $config->getId();
                  $config->name;
                  }