Magento – How to get a category thumbnail or Image

categorymagento-1thumbnail

I am stuck at this point. I want to display a grid of categories thumbnail/image

var_dump($_category->getData('thumbnail')); return NULL

Even when I do var_dump($_category->getData());
here is what's return

array(16) { ["entity_id"]=> string(1) "3" ["entity_type_id"]=>string(1) "3"     
["attribute_set_id"]=> string(1) "3" ["parent_id"]=> string(1) "2" 
["created_at"]=> string(19) "2014-12-15 18:49:50" ["updated_at"]=> string(19) 
"2014-12-15 19:09:30" ["path"]=> string(5) "1/2/3" ["position"]=> string(1) 
"1" ["level"]=> string(1) "2" ["children_count"]=> string(1) "0" ["path_id"]=> 
string(5) "1/2/3" ["is_active"]=> string(1) "1" ["include_in_menu"]=> 
string(1) "1" ["request_path"]=> string(14) "vegetable.html" ["name"]=> 
string(9) "Vegetable" ["url_key"]=> string(9) "vegetable"}

this is my code

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php if (count($_categories) > 0): ?>
<ul>
    <?php foreach($_categories as $_category): ?>
        <li>
            <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                <?php echo $_category->getName(); // this works?>
                <?php var_dump($_category->getData('thumbnail')) // return null?>
            </a>
        </li>
    <?php endforeach; ?>
</ul>
<?php endif; ?>

Best Answer

You could use

echo Mage::getModel('catalog/category')->load($catId)->getThumbnailImageUrl();

But you would have to make some changes to

/app/code/core/Mage/Catalog/Model/Category.php

Before editing, copy this file to local and then insert the following code around line 494

/**
 * Retrieve Thumbnail image URL
 *
 * @return string
 */
public function getThumbnailImageUrl()
{
    $url = false;
    if ($image = $this->getThumbnail()) {
        $url = Mage::getBaseUrl('media').'catalog/category/'.$image;
    }
    return $url;
}
Related Topic