【发布时间】:2025-12-12 14:50:02
【问题描述】:
我添加了magento add custom input field to customer account form in admin中描述的自定义字段
但我想要一个选择列表,而不仅仅是一个文本输入列表。我不知道我必须设置哪种参数以及如何告诉可能值的列表。
请帮忙:)
谢谢,
植物
【问题讨论】:
我添加了magento add custom input field to customer account form in admin中描述的自定义字段
但我想要一个选择列表,而不仅仅是一个文本输入列表。我不知道我必须设置哪种参数以及如何告诉可能值的列表。
请帮忙:)
谢谢,
植物
【问题讨论】:
你可能会在哪里做类似的事情:
$setup->addAttribute('customer', 'custom_attribute', array(
'type' => 'text',
'label' => 'Customer Custom Attribute',
));
改用这些值:
$setup->addAttribute('customer', 'custom_attribute', array(
'type' => 'int',
'label' => 'Customer Custom Attribute',
'input' => 'select',
'source' => 'eav/entity_attribute_source_boolean',
));
type 是int,因为您通常会存储所选值的索引,而不是值本身。 input 是 select,因此管理员渲染器知道要使用哪个控件。此处显示的source 是一个常见示例,它提供了一个带有数字索引的“是”和“否”值数组。
Magento 代码中已经有许多源模型可供您使用,您也可以创建自己的模型,查看任何现有模型以了解它如何返回数组。如果您自己制作并且使用文本索引而不是数字索引,则必须将 type 改回 text。
【讨论】:
尝试在你的模块设置文件中添加这个
'value' => array('notate_to_zero'=>array(0=>'Bleu',0=>'Rouge',0=>'Vert',0=>'Violet',0=>'Noir',0=>'Orange'))
),
或者看看这个 --> http://inchoo.net/ecommerce/magento/how-to-create-custom-attribute-source-type/
【讨论】: