Magento 1.7 – How to Create Drop Down Attributes for Customer

attributesmagento-1.7

I want to introduce a new field in customer admin area and I just want to have it two options "yes" or "no"

here is my code that is creating simple text fields but I am not sure how can I create drop down attribute for the customer?

$installer->startSetup();
$vCustomerEntityType = $installer->getEntityTypeId('customer');
$vCustAttributeSetId = $installer->getDefaultAttributeSetId($vCustomerEntityType);
$vCustAttributeGroupId = $installer->getDefaultAttributeGroupId($vCustomerEntityType,$vCustAttributeSetId);
$installer->addAttribute('customer', 'testveri', array(
    'label' => 'Working?',
    'input' => 'text',
    'type'  => 'varchar',
    'forms' => array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'),
    'required' => 0,
    'user_defined' => 0,
));
$installer->addAttributeToGroup($vCustomerEntityType, $vCustAttributeSetId,     $vCustAttributeGroupId, 'testveri', 0);
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'testveri');
$oAttribute->setData('used_in_forms', array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'));
$oAttribute->save();
$installer->endSetup();

Can anybody help me in creating a drop down attribute for admin panel only?

Best Answer

Try this:

$installer->addAttribute('customer', 'testveri', array(
    'label' => 'Working?',
    'input' => 'select',
    'type'  => 'int',
    'required' => 0,
    'user_defined' => 0,
    'source' => 'eav/entity_attribute_source_table',
    'option' => array('values' => array('Value 1', 'Value 2', 'Value 3')) 
));

EDIT
Add the new attribute as a column in the grid.
Override the default customer grid and in _prepareColumns add this:

protected function _prepareColumns(){ 
    $values = array(
        1   => Mage::helper('customer')->__('Yes'),
        0   => Mage::helper('customer')->__('No') 
    );
    $this->addColumnAfter('testveri', array( 
        'header' => Mage::helper('customer')->__('Working?'), 
        'index' => 'testveri', 
        'type'      =>  'options',
        'options'   =>  $values, 
    ),'email'); 
    return parent::_prepareColumns(); 
}
Related Topic