在magento 2中添加自定义属性 [英] Add custom attribute in magento 2

查看:519
本文介绍了在magento 2中添加自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将自定义字段添加到前端注册表单. 我已经按照

How to add a custom field to the frontend registration form. I already added required feilds in database by following

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
    $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
    $eavSetup->addAttribute(
        \Magento\Customer\Model\Customer::ENTITY,
        'sample_attribute',
        [
            'type'         => 'varchar',
            'label'        => 'Sample Attribute',
            'input'        => 'text',
            'required'     => false,
            'visible'      => true,
            'user_defined' => true,
            'position'     => 999,
            'system'       => 0,
        ]
    );
    $sampleAttribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'sample_attribute');

    // more used_in_forms ['adminhtml_checkout','adminhtml_customer','adminhtml_customer_address','customer_account_edit','customer_address_edit','customer_register_address']
    $sampleAttribute->setData(
        'used_in_forms',
        ['adminhtml_customer']

    );
    $sampleAttribute->save();
}

我的领域在magento管理员中列出.我无法在前端显示它

my feild listed in magento admin. I'm unable to display it in frontend

推荐答案

customer_account_create.xml 的路径应为Vendor_Module\view\frontend\layout\.

对于那些刚接触 Magento 的人来说,准确地知道所有文件名和文件路径约定对于避免花费时间搜索错误非常重要.

For those who are new to Magento and do not know about all the filename and filepath conventions to be precise is very important to avoid spending time searching for errors.

这篇关于在magento 2中添加自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆