【发布时间】:2020-09-27 15:43:24
【问题描述】:
只是想知道为什么以下脚本似乎将新记录添加到 eav_attribute 和 catalog_eav_attribute 但当我编辑产品时该属性并未显示在管理员中:
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Ash\GiftWrapFee\Setup;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* Eav setup factory
* @var EavSetupFactory
*/
private $eavSetupFactory;
/**
* Init
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(\Magento\Eav\Setup\EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$eavSetup = $this->eavSetupFactory->create();
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'giftwrapfee_applied',
[
'group' => 'General',
'type' => 'text',
'label' => 'Apply Giftwrap Charge',
'input' => 'select',
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
'frontend' => '',
'backend' => '',
'required' => false,
'sort_order' => 50,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'is_used_in_grid' => false,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false,
'visible' => true,
'is_html_allowed_on_front' => true,
'visible_on_front' => true
]
);
}
}
在此之后我运行 bin/magento setup:upgrade 然后就像我说的那样,表在数据库中正确更新但由于某种原因,当我在管理区域中签入目录产品时没有属性。
感谢大家的帮助!
【问题讨论】:
标签: magento2 admin entity-attribute-value