简体   繁体   中英

magento add custom input field to customer account form in admin

I am trying to add a custom input field to the account information tab of a customer in admin. i have successfully been able to create a custom attribute in the eav table for my input, but have been unsuccessful in finding how to make my input show up. curious of anyone has any good resources on how to do this?

The above link doesn't work anymore. I found a better explanation at http://www.excellencemagentoblog.com/customer-registration-fields-magento1-6 . If you just do the first steps you will only have the added fields in the admin.

You have to tell the attribute which forms it's used in:

Mage::getModel('customer/attribute')
    ->loadByCode('customer', 'your_attrib_code')
    ->setUsedInForms(array('adminhtml_customer'))
    ->save();

This can be put in a standard Magento upgrade script for convenience (usually the same script that originally created the attribute, or the one right after it).

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

define('MAGENTO', realpath(dirname(__FILE__)));
ini_set('memory_limit', '32M');
set_time_limit (0);
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,
        ));                
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM