Plantex
Plantex

Reputation: 1

Add a dropdown list as custom field in magento

I added custom fields as described in magento add custom input field to customer account form in admin

But I want a select list, not only a text input one. I don't know which kind of parameter I have to set and how to tell the list of possible values.

Please help :)

Thanks,

Plantex

Upvotes: 0

Views: 8637

Answers (2)

seif
seif

Reputation: 1

Try adding this at your module setup file

'value'  => array('notate_to_zero'=>array(0=>'Bleu',0=>'Rouge',0=>'Vert',0=>'Violet',0=>'Noir',0=>'Orange'))
                    ),

or look at this --> http://inchoo.net/ecommerce/magento/how-to-create-custom-attribute-source-type/

Upvotes: 0

clockworkgeek
clockworkgeek

Reputation: 37700

Where you might do something like:

$setup->addAttribute('customer', 'custom_attribute', array(
    'type'      =>  'text',
    'label'     =>  'Customer Custom Attribute',
));

Use these values instead:

$setup->addAttribute('customer', 'custom_attribute', array(
    'type'      =>  'int',
    'label'     =>  'Customer Custom Attribute',
    'input'     =>  'select',
    'source'    =>  'eav/entity_attribute_source_boolean',
));

The type is int because you will typically be storing the index of the value chosen, not the value itself. The input is select so the admin renderer knows which control to use. The source shown here is a common example, it provides an array of "Yes" and "No" values with numeric indexes.

There are many source models already in the Magento code that you can use and you can create your own too, look at any existing one to see how it returns an array. If you make your own and if it uses text indexes instead of numeric then the type will have to be changed back to text.

Upvotes: 3

Related Questions