$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('customer', 'your_attribute_code_here', array(
'input' => 'text',
'type' => 'int',
'label' => 'Some textual description',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
));
$entityTypeId = $setup->getEntityTypeId('customer');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'your_attribute_code_here',
'999' //sort_order
);
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'your_attribute_code_here');
$oAttribute->setData('used_in_forms', array('adminhtml_customer'));
$oAttribute->save();
$setup->endSetup();
添加属性的不寻常步骤是,setData('used_in_forms')
这似乎是客户属性所独有的。没有它,该字段将不会被渲染,无论如何当然不会在adminhtml中。您可以在customer_form_attribute
数据库表中看到此数组的有效选项。
就将a select
与预定义选项一起使用而言,这是您需要的:
$iAttributeId = $installer->getAttributeId($entityTypeId, 'your_attribute_code_here');
$aClasses = array('TV','DVD','Home Theatre','Air Conditioner','Stereo/Hifi','Game Console','Camcorder','VCR','Set Top @R_757_2419@','PVR');
$aOption = array();
$aOption['attribute_id'] = $iAttributeId;
for($iCount=0;$iCount<sizeof($aClasses);$iCount++){
$aOption['value']['option'.$iCount][0] = $aClasses[$iCount];
}
$setup->addAttributeOption($aOption);
希望这对您有帮助, 京东