2013-10-15 58 views
0

我试图在我的magento后端类别中有一个multiselect选项。自定义类别属性

我有以下代码:

$installer = $this; 
$installer->startSetup(); 
$attribute = array( 
     'group' => "General Information", // and this one 
     'label' => 'Location', 
     'type' => 'varchar', 
     'input' => 'multiselect', 
     'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, 
     'visible' => true, 
     'required' => false, 
     'is_user_defined' => true, 
     'option'=> array (
       'value' => array(
         'england'=> array( 
         0 =>'England'), 
         'scotland'=> array( 
         0 =>'Scotland') 
         ) 
       ) 
    ); 

$installer->addAttribute('catalog_category', 'bottom_description', $attribute); 
$installer->endSetup(); 

这会在后台一个新的属性,但没有价值。

我需要配置其他任何东西,以便我可以看到这些值吗?

感谢

编辑:

在config.xml中我有:

<version>0.8.0</version> 

我有另外一个文件:

mysql4-upgrade-0.7.0-0.8.0.php

该文件似乎不当我清除缓存并访问类别时运行。

任何想法?

回答

1

你在mysql4-upgrade脚本中编写脚本的上面对吗?你有更新config.xml版本 ,因为它只有在config.xml中升级版本时才执行 所以请检查它

+0

是的。每次运行上面的命令,我都会增加'0.4.0','0.5.0'等版本并重命名文件'mysql4-upgrade-0.0.1-0.4.0.php','mysql4-upgrade-0.0.1 -0.5.0.php'匹配。但清除缓存后仍然没有值 – user1970557

+0

版本应该更新为例如 upgrade-0.0.1-0.4.0.php到mysql4-upgrade-0.4.0-0.5.0.php – shivam

+0

啊,那可能是问题了。它不是拾取我一直在做的任何更改 – user1970557

1

Arrr ....你很近。它应该是'value' => array(....),而不是'values' => array(...)
但我在这里看到一个问题。向属性添加选项时,选项值应为int值。
假设您在代码中添加属性并使用LocationEngland,Scotland保存产品。数据库中的值不会是england,scotland将会是类似于:76,77。自动生成的选项苏格兰和英格兰选项。如果要将值保存为england,scotland,则需要为此属性编写自定义源模型。
You can find here an example and adapt it to your needs.

0

要在类别部分添加自定义yes/no属性,请创建模块并输入以下代码。

<?php 
$this->startSetup(); 
$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'featured_product', array(
    'group'   => 'General Information', 
    'input'   => 'select', 
    'type'   => 'text', 
    'label'   => 'Featured Category', 
    'backend'  => '', 
    'visible'  => true, 
    'required'  => false, 
    'visible_on_front' => true, 
    'global'  => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 
    'source' => 'eav/entity_attribute_source_boolean', 
));?> 

请参考我的教程。

http://www.pearlbells.co.uk/how-to-add-custom-attribute-dropdown-to-category-section-magento/