Friday 21 February 2014

Magento : Show Any Category on Home Page

Create a homcategory.phtml inside a
app/design/frontend/your_themes/default/template/catalog/category

copy this code in the .phtml file

<?php 
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
$i=1;

$_category=Mage::getModel('catalog/category')->load($this->getCategoryId());
    $thumburl = Mage::getBaseUrl('web').'media/catalog/category/'.$_category->getThumbnail(); 
?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?> ">
<img  src="<?php echo $thumburl; ?>" alt="thumb" height="125" width="115" />
<span class="thumb_title">
<?php echo html_entity_decode($_category->getName()) ?>
</span>
</a>
</li>

<?php if ($i==7):
break;
endif;
$i++;
?>

After doing this Login in magento admin,

Go to CMS > static block - and create a static block

Block Title : Your BLock Name (as you like)

Identifier : your_block_id (as you like)

Status : Enabled / Disbaled .

Click to Show/ hide Editor and copy and past this content in content block

<div class="product_category">
<ul id="style_block">
{{block type="core/template" category_id="3" template="catalog/category/homcategory.phtml"}}
{{block type="core/template" category_id="7" template="catalog/category/homcategory.phtml"}}
</ul>
<h4>Choose from a variety of shirt styles</h4>
</div>

Note :- ( category_id="3") as you show a category in your home page.

after that save block.

And go to the CMS > Pages select a Home Page

and select a Content Tab, Click to Show/ hide Editor

{{block type="cms/block" block_id="your_block_id"}}

and paste this code.

that Done!

Output Look like this...

Refresh your home page and you see the list Category by as your choose....

Wednesday 19 February 2014

Magento : Add Image in Magento Admin Product Grid

Step 1:
  First you need to copy the core block to local. Copy Grid.php from       app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php to
  app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php


Here you'll find a method named _prepareColumns(), add the below code within this method
 If yoy edit in Notepad++ go to the line number 145.
       

$this->addColumn('product_image', array(
              'header'    => Mage::helper('catalog')->__('Image'),
              'align'     =>'left',
              'index'     => 'entity_id',
              'width'     => '100px',
              'renderer'  => 'Mage_Adminhtml_Block_Catalog_Product_Renderer_Image'
        ));


Step 2: 
    Now create the renderer file named Image.php in the following path
    app/code/local/Mage/Adminhtml/Block/Catalog/Product/Renderer/Image.php
    Here add the below code..
   
class Mage_Adminhtml_Block_Catalog_Product_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
    {
        public function render(Varien_Object $row)
        {
            $_product = Mage::getModel('catalog/product')->load($row->getEntityId());
            if($_product->getImage() != 'no_selection'){
                  $image = "<img src='".Mage::helper('catalog/image')->init($_product, 'image')->resize(100)."' title='".$_product->getName()."' />";
            }
            return $image;
        }

    }