Return to Snippet

Revision: 49783
at July 29, 2011 20:48 by necode


Initial Code
require_once MAGENTO . '/../app/Mage.php';
Mage::app();

$newFields = array(
    'custom_attribute' => array(
        'type'              => 'text',
        'label'                => 'Customer Custom Attribute'
    )
);

$entities = array('customer');

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
foreach($newFields as $attributeName => $attributeDefs) {
    foreach ($entities as $entity) {
        $setup->addAttribute($entity, $attributeName, array(
            'position'          => 1,
            'type'              => $attributeDefs['type'],
            'label'             => $attributeDefs['label'],
            'global'            => 1,
            'visible'           => 1,
            'required'          => 0,
            'user_defined'      => 1,
            'searchable'        => 0,
            'filterable'        => 0,
            'comparable'        => 0,
            'visible_on_front'  => 1,
            'visible_in_advanced_search' => 0,
            'unique'            => 0,
            'is_configurable'   => 0,
            'position'          => 1,
        ));                
    }
}

OR

<?php

$installer = $this;

$installer->startSetup();
    
$installer->addAttribute('customer', 'interested',array(
	'type'      => 'varchar',
	'input'		=> 'text',
	'visible'   => true,
	'label'     => 'Interested sales',
 	'global'    => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
	'required'	=> false
)); 

$installer->endSetup();

Initial URL
http://stackoverflow.com/questions/5185727/magento-add-custom-input-field-to-customer-account-form-in-admin

Initial Description
The fastest way is to create a php file and access it through browser add the following content to file.

Initial Title
Magento add custom input field to customer account form in admin

Initial Tags
customer, magento

Initial Language
PHP