如何解决自定义产品属性未在管理员中显示Magento 2.4.0
只是想知道为什么以下脚本似乎将新记录添加到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,然后像我说的那样,表在数据库中正确更新,但是由于某些原因,当我在管理区域中检入目录产品时没有属性。
感谢大家的帮助!
解决方法
好吧,我为不久以后可能在同一问题上绊倒的任何其他人弄清楚了这一点。解决方法是基本上进行更新:
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
到
'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。