简体   繁体   中英

Add Customer Field and use in own forms in Magento 1.7

I added new customer fields in module my module update:

    $installer = $this;
$installer->startSetup();
$_attributeToAdd = [
    'recordtype'=>[
        'input'=>'select',
        'type'=>'varchar',
        'label'=>Mage::helper('company_partner')->__('String'),
        'visible'=>1,
        'required'=>1,
        'user_defined'=>1,
        'global'=>1,
        'visible_on_front'=>1,
        'source'=>'company_partner/entity_recordtype'

    ],
    'court'=>[
        'input'=>'text',
        'type'=>'varchar',
        'label'=>Mage::helper('company_partner')->__('String),
        'visible'=>1,
        'required'=>0,
        'user_defined'=>1
    ],
    'krs'=>[
        'input'=>'text',
        'type'=>'varchar',
        'label'=>Mage::helper('company_partner')->__('String'),
        'visible'=>1,
        'required'=>0,
        'user_defined'=>1
    ],
    ...other fields
];
    $_order=2200;
    foreach($_attributeToAdd as $_key=>$_value){
        if(isset($setup)){
            unset($setup);

        }
        if(isset($_oAttribute)){
            unset($_oAttribute);
        }
        $setup = Mage::getModel('customer/entity_setup', 'core_setup');

        $_entitytypeId = $setup->getEntityTypeId('customer');
        $_attributeTypeId = $setup->getDefaultAttributeSetId($_entitytypeId);
        $_attributeGroupId = $setup->getDefaultAttributeGroupId($_entitytypeId,$_attributeTypeId);

        $setup->addAttribute('customer',$_key,$_value);
        $setup->addAttributeToGroup($_entitytypeId,$_attributeTypeId,$_attributeGroupId,$_key,$_order);

        Mage::getSingleton('eav/config')->getAttribute('customer', $_key)->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register','unizeto_partner_account_edit','magestore_affiliateplus_account_edit'))->save();

        $_oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer',$_key);
        $_oAttribute->setData('used_in_forms',['adminhtml_customer']);
        $_oAttribute->save();
        $_order++;
    }

$installer->endSetup();

I tryed also in

$_oAttribute->setData('used_in_forms',['adminhtml_customer','company_module']);

And I see this attributes in admin panel (add/edit customoer) but in my own module I can't use in forms/action controller (can't see filed in admin data).

I don't know why.

My module overwrite form and action controller from other not core magento module.

You can use This link

to create customer attribute.This is safe.

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