Home    Articles

 

How to set programmatically category image in Magento

 

1. First you need to load your category by id.

2. Make sure you have your category image in this folder: magento_root/media/catalog/category/images/ 

3. Set the image to loaded category object

4. Save.

$categoryObj = Mage::getModel('catalog/category')->load($categoryId);
$categoryObj->setImage('images/my_image.jpg'); // magento knows that this is relative path
$categoryObj->save();

 

by