【问题标题】:Adding attributes to user entity via. install script通过向用户实体添加属性。安装脚本
【发布时间】:2013-09-09 07:30:41
【问题描述】:

我最近获得了一份新的实习机会,我必须使用 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();

?>

【问题讨论】:

    标签: php xml magento


    【解决方案1】:

    只需稍作改动

    使用喜欢

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

    【讨论】:

    • 今天晚些时候我会试一试。 :) 如果您不介意我问,如果我已经创建了一个名为“hairtype”的属性,我将如何将其从文本字段更新为选择框?
    • 抱歉,无法以编程方式进行更新。可以更改数据库中的字段。但它很复杂。宁愿删除属性创建一个新的
    • 如何删除?可以通过更新或安装脚本来完成吗? :)
    • 如何以编程方式删除属性?
    猜你喜欢
    • 1970-01-01
    • 2014-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多