2012-07-30 37 views
11

Tôi là một newbie với magento. Tôi muốn thêm hai trường hình ảnh tùy chỉnh vào một danh mục. Tôi đã tạo một mô-đun với tệp trình cài đặt cho mô-đun của mình:Làm cách nào để thêm trường hình ảnh tùy chỉnh vào một danh mục trong 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(); 

Tôi có thể xem trường hình ảnh khi chỉnh sửa hoặc thêm danh mục mới nhưng không lưu vào cơ sở dữ liệu. Làm thế nào để làm cho nó hoạt động? Cảm ơn

Trả lời

29

Để thêm một thuộc tính hình ảnh mới cho các hạng mục, bạn cần phải sử dụng những giá trị trong thiết lập của bạn:

'type' => 'varchar', 
'input' => 'image', 
'backend' => 'catalog/category_attribute_backend_image', 

thay vì những cái:

'input' => 'image', 
'type' => 'file', 
+2

Cảm ơn bạn rất nhiều! – Joonas

+1

Năm cũ ... và vẫn giúp mọi người! Cảm ơn! – eklingen

Các vấn đề liên quan