Magento2.1.5如何在客户注册表单上添加多个自定义字段(管理面板)

时间:2017-04-11 08:09:52

标签: magento-2.0

我已在管理员端的客户注册表单中添加了单个字段。

但我想再添加一个(multipul字段)。这是我的代码。

      $customerSetup->addAttribute(Customer::ENTITY, 'Company_name', [
        'type' => 'varchar',
        'label' => 'Company Name tst3',
        'input' => 'text',           
        'required' => true,
        'sort_order' => 1000,
        'position' => 1000,
        'system' => 0,

    ]);       
    $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'Company_name')
    ->addData([
        'attribute_set_id' => $attributeSetId,
        'attribute_group_id' => $attributeGroupId,
        'used_in_forms' => ['adminhtml_customer'],
        'used_in_forms' => ['customer_account_create'],
    ]);

这是添加单个字段的代码,它工作正常。 现在我正在尝试添加一个字段的代码。

     $customerSetup->addAttribute(Customer::ENTITY, 'Company_name', [
        'type' => 'varchar',
        'label' => 'Company Name tst3',
        'input' => 'text',           
        'required' => true,
        'sort_order' => 1000,
        'position' => 1000,
        'system' => 0,

    ],'Admin_email', [
        'type' => 'varchar',
        'label' => 'Admin Email',
        'input' => 'input',
        'required' => true,
        'sort_order' => 1000,
        'position' => 1000,           
    ]);       
    $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'Company_name','Admin_email')
    ->addData([
        'attribute_set_id' => $attributeSetId,
        'attribute_group_id' => $attributeGroupId,
        'used_in_forms' => ['adminhtml_customer'],
        'used_in_forms' => ['customer_account_create'],
    ]);

1 个答案:

答案 0 :(得分:0)

你可以通过将所需的属性放在像这样的数组中来实现它

$attributesInfo = [
        'attribut1' => [
            'type' => 'varchar',
            'label' => 'Company Name tst3',
            'input' => 'text',           
            'required' => true,
            'sort_order' => 1000,
            'position' => 1000,
            'system' => 0,
        ],
        'attribut2' => [
            'type' => 'varchar',
            'label' => 'Admin Email',
            'input' => 'text',           
            'required' => true,
            'sort_order' => 1000,
            'position' => 1000,
            'system' => 0,
        ],
    ];

foreach ($attributesInfo as $attributeCode => $attributeParams) {
        $customerSetup->addAttribute(Customer::ENTITY, $attributeCode, $attributeParams);
    }

然后涉及eav的另一部分

$companyAttribute= $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'attribute1');
    $companyAttribute->addData([
        'attribute_set_id' => $attributeSetId,
        'attribute_group_id' => $attributeGroupId,
        'used_in_forms' => ['handle1','handle2'],
    ]);
$adminEmailAttribute= $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'attribute2');
    $adminEmailAttribute->addData([
        'attribute_set_id' => $attributeSetId,
        'attribute_group_id' => $attributeGroupId,
        'used_in_forms' => ['handle1','handle2'],
    ]);

这是一个不错的教程(2.1或更高版本)

http://www.extensions.sashas.org/blog/magento-2-1-3-how-to-make-customer-attribute-update.html

应该在magento.stackexchange中询问

相关问题