Magento – how to add “gender” resp. a salutation to customer address

addressadminhtmlcustomermagento-1.7

I like to add gender (or a salutation) to the customer's address. While the gender already for a customer exists, I thought I can simply reuse it but somehow I get stuck at the source model which should populate the values for the gender dropdown.

Problem: The field "Gender" appears as drop-down in my customer address section in the admin backend but has no options which I can choose.

So here a summary of what I did. Basically, I followed the steps at these 2 pages:

But I didn't extend the model for the customer's address, because I think it is not necessary?

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('customer_address', 'gender', array(
        'type' => 'int',
        'input' => 'select',
        'label' => 'Gender',
        'global' => 1,
        'visible' => 1,
        'required' => 0,
        'user_defined' => 1,
        'default' => '0',
        'visible_on_front' => 1,
        'source' => 'eav/entity_attribute_source_table',
));

Mage::getSingleton('eav/config')
->getAttribute('customer_address', 'gender')
->setData('used_in_forms', array('adminhtml_customer_address'))
->save();

While I am "reusing" source model "eav/entity_attribute_source_table" from the customer gender I thought it would be automatically populated with the options. But it is not the case. Any ideas what I missed or need to be modified? Thank you in advance.

Best Answer

Your only problem is, that the dropdown is empty, isn't it?

To fill this dropdown: System > Configuration > Customers > Customer Configuration > Name and Address Options > Prefix Dropdown Options just fill in, whatever you want.

Protip: If you want to have radio buttons instead, you have to array_filter() in your template, because there is an empty option added ;-)