0

我最近得到了一份新的实习,我必须使用 Magento 编程,这是我以前从未尝试过的。我当前任务的一部分是为我们的客户实体添加一些额外的属性,然后这些属性将显示在后端。

此时我已经设法添加一个属性,它是后端的一个文本字段,但我真正想做的是添加一个带有预定义选项的选择框。每当我尝试这样做时,我的 Magento 都会损坏,以至于我必须重新安装整个东西。我现在正把头靠在墙上。

我是通过这样做的。一个安装脚本,来自我创建的模块。

下面我粘贴了我的安装脚本,但如果您需要查看更多代码,请告诉我。

mysql4-install-0.1.0.php:

<?php 

$installer = $this;
$installer->startSetup();

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$entityTypeId     = $setup->getEntityTypeId('customer');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$setup->addAttribute('customer', 'skintype', array(
    'input'         => 'select',
    'type'          => 'varchar',
    'option'        => array(
                                'optionone' => array('zero' => array(0 => 'normal hud')),
                                'optiontwo' => array('one' => array(1 => 'tør hud')),
                                'optionthree' => array('two' => array(2 => 'fedtet hud')),
                                'optionfour' => array('three' => array(3 => 'kombineret hud')),
                                'optionfive' => array('four' => array(4 => 'sensibel hud'))
                            ),  
    'default'       => array('optionone'),
    'label'         => 'Skintype',
    'visible'       => 1,
    'required'      => 0,
    'user_defined' => 1,
));

$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'skintype');
$oAttribute->setData('used_in_forms', array('adminhtml_customer'));
$oAttribute->save();

$setup->endSetup();

?>
4

1 回答 1

0

只需稍作改动即可

使用喜欢

'option' => array ( 'value' => array( '0'=>array(0=>'Small'), '1'=>array(0=>'Medium'), '2'=>array(0=>'Large'), ) ),

于 2013-09-09T08:15:49.923 回答