2014-03-28 99 views
0

我一直在試圖通過編程方式爲後端magento中的類別創建一個屬性。所以,我遵循http://www.hesselbom.net/magento-custom-attributes-with-selectbox中的步驟,它完美地工作,甚至我可以保存選定的值。而如果我嘗試創建文本框屬性,則值不會被保存。任何人都可以指導我如何做到這一點?在magento中保存類別的自定義屬性值

以下是我的代碼。

$installer->addAttribute('catalog_category', 'custom_textfield', array(
'type' => 'varchar', 
'label' => 'Custom field', 
'input' => 'text', 
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, 
'visible' => TRUE, 
'required' => FALSE, 
'default' => '' 
)); 

$attributeId = $installer->getAttributeId($entityTypeId, 'custom_textfield'); 

我也相應地更新了配置文件中的版本。

回答

0

請它嘗試爲我工作

$installer->addAttribute('catalog_category', 'custom_textfield', array( 
    'group'   => 'General', 
    'input'   => 'text', 
    'type'   => 'varchar', 
    'label'   => 'Custom field ', 
    'backend'  => '', 
    'visible'  => 1, 
    'required'  => 0, 
    'user_defined' => 1, 
    'global'  => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 
    )); 
+0

不,它不適合我。 –

+0

它顯示在類別中,或者你檢查數據庫的條目? –

+0

在哪裏以及如何操作?由於我是magento新手,我不知道該在哪裏做? –

0

$this->addAttribute('catalog_category', 'custom_textfield', array( 'group' => 'General', 'type' => 'varchar',//can be int, varchar, decimal, text, datetime 'backend' => '', 'frontend_input' => '', 'frontend' => '', 'label' => 'Custom Field', 'input' => 'image', //text, textarea, select, file, image, multilselect 'class' => '', 'source' => '[source model for attribute here]',//this is necessary for select and multilelect, for the rest leave it blank 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//scope can be SCOPE_STORE or SCOPE_GLOBAL or SCOPE_WEBSITE 'visible' => true, 'frontend_class' => '', 'required' => false,//or true 'user_defined' => true, 'default' => '', 'position' => 100,//any number will do ));

這應該做的伎倆。 :)

0

經過漫長的搜索,我發現它。以下是在管理面板上創建和保存屬性值的方法。

$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); 

$setup->addAttribute('catalog_category', 'length_waterline_custom', array(
'group'   => 'General', 
'input'   => 'text', 
'type'   => 'varchar', 
'label'   => 'Length of Waterline', 
'backend'  => '', 
'visible'  => 1, 
'required'  => false, 
'user_defined' => 1, 
'global'  => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 
)); 

$eavConfig = Mage::getSingleton('eav/config'); 
相關問題