繁体   English   中英

在Magento 1.7中添加客户字段并以自己的形式使用

[英]Add Customer Field and use in own forms in Magento 1.7

我在模块更新中添加了新的客户字段:

    $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();

我也尝试过

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

而且我在管理面板(添加/编辑客户)中看到了此属性,但是在我自己的模块中,我无法在表单/动作控制器中使用(看不到管理数据中的文件)。

我不知道为什么

我的模块从其他非核心的magento模块覆盖了表单和动作控制器。

您可以使用此链接

创建客户属性。这很安全。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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