如何将自定义图像字段添加到Magento中的类别?

Joo*_*nas 12 magento

我是magento的新手.我想在一个类别中添加两个自定义图像字段.我已经为我的模块创建了一个带有安装程序文件的模块

$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();
Run Code Online (Sandbox Code Playgroud)

我可以在编辑或添加新类别时看到图像字段,但不保存到数据库.如何使它工作?谢谢

blm*_*age 31

要为类别添加新的图像属性,您需要在设置中使用这些值:

'type'    => 'varchar',
'input'   => 'image',
'backend' => 'catalog/category_attribute_backend_image',
Run Code Online (Sandbox Code Playgroud)

而不是那些:

'input' => 'image',
'type'  => 'file',
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢! (2认同)
  • 年纪大了……仍然在帮助别人!谢谢! (2认同)