【问题标题】:Custom Product Attribute Not Showing In Admin (Magento 2.4.0)自定义产品属性未显示在管理中 (Magento 2.4.0)
【发布时间】:2020-09-27 15:43:24
【问题描述】:

只是想知道为什么以下脚本似乎将新记录添加到 eav_attributecatalog_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


    【解决方案1】:

    好的,我为在不久的将来可能会遇到同样问题的其他人解决了这个问题。修复基本上是更新:

    'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
    

    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
    

    【讨论】:

      【解决方案2】:

      $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-03
        • 1970-01-01
        • 1970-01-01
        • 2022-11-11
        • 1970-01-01
        • 2011-01-15
        相关资源
        最近更新 更多