我没有任何特别之处。我用于Product的逻辑相同,我在Admin页面的Product grid中看到自定义属性值,但在Customer grid中没有。
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
\Magento\Customer\Model\Customer::ENTITY,
'my_custom_field',
[
'type' => 'varchar',
'frontend' => '',
'label' => __('My Custom Field'),
'input' => 'multiselect',
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Table',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'required' => false,
'system' => false,
'visible' => true,
'user_defined' => false,
'searchable' => false,
'filterable' => true,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => '',
'group' => 'General',
'is_used_in_grid' => true,
'is_visible_in_grid' => true,
'is_filterable_in_grid' => true,
'position' => 600,
'option' => [
'values' => [
'Var1',
'Var2',
'Var3'
]
]
]
);
$my_custom_field = $this->eavConfig->getAttribute(\Magento\Customer\Model\Customer::ENTITY, 'my_custom_field');
$my_custom_field->setData(
'used_in_forms',
[
'adminhtml_customer',
'customer_account_edit'
]
);
$my_custom_field->save();
如果这是Magento 2中的错误,我会打开机票,但如果我弄错了或忘记了什么,有人会帮助我:)