2013-10-15 207 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/