How to add a custom image field to a category in Magento?

Viewed 11082

I'm a newbie with magento. I want to add two custom image fields to a category. I have created a module with installer file to my module:

$installer = $this;
$installer->startSetup();

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId     = $setup->getEntityTypeId('catalog_category');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$setup->addAttribute('catalog_category', 'image1', array(
    'input'         => 'image',
    'type'          => 'file',
    'group' => 'General',
    'label'         => 'Additional image 1',
    'visible'       => 1,
    'required'      => 0,
    'user_defined' => 1,
    'frontend_input' =>'',
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible_on_front'  => 1,
));

$setup->addAttributeToGroup(
 $entityTypeId,
 $attributeSetId,
 $attributeGroupId,
 'image1',
 '999'  //sort_order
);

$installer->endSetup();

I can see the image field when editing or adding new category but its not saving to database. How to make it work? Thanks

1 Answers
Related