【发布时间】:2018-09-24 20:02:34
【问题描述】:
我创建了一个文件setup/installdata.php:
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
private $eavSetupFactory;
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'name',
[
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'attrlabel',
'input' => 'select',
'class' => '',
'source' => 'a\b\Model\Attribute\Source\m',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => '',
'attribute_set' => 'Default',
]
);
}
}
然后,在 etc/module.xml 中,我有:
<module name="Conlabz_IdentityCheck" setup_version="1.0.0" />
但我仍然没有看到创建的属性。
我还尝试了以下方法:
在 Magento 根文件夹中,我运行以下命令:
php bin/magento module:disable
php bin/magento module:enable
php bin/magento setup:upgrade
php bin/magento cache:flush
全部成功,没有错误,但正如我所说,它不起作用。
我做错了什么?
【问题讨论】:
标签: attributes product magento2