skip to Main Content

Just wondering why the following script seems to to add the new records to eav_attribute and catalog_eav_attribute yet the attribute doesn’t show up in the admin when I edit a product:

<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace AshGiftWrapFeeSetup;

use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;

/**
 * @codeCoverageIgnore
 */
class InstallData implements InstallDataInterface
{
    /**
     * Eav setup factory
     * @var EavSetupFactory
     */
    private $eavSetupFactory;

    /**
     * Init
     * @param EavSetupFactory $eavSetupFactory
     */
    public function __construct(MagentoEavSetupEavSetupFactory $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(
            MagentoCatalogModelProduct::ENTITY,
            'giftwrapfee_applied',
            [
                'group' => 'General',
                'type' => 'text',
                'label' => 'Apply Giftwrap Charge',
                'input' => 'select',
                'source' => 'MagentoEavModelEntityAttributeSourceBoolean',
                'frontend' => '',
                'backend' => '',
                'required' => false,
                'sort_order' => 50,
                'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::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
            ]
        );
    }
}

After this I ran bin/magento setup:upgrade and then like I say, the tables update correctly in the database but for some reason, there is no attribute when I check in the catalog products in the admin area.

Thanks guys for any help!

2

Answers


  1. Chosen as BEST ANSWER

    Ok, I figured this out for anyone else who may stumble on the same issue in the near future. The fix was to basically to update:

    'source' => 'MagentoEavModelEntityAttributeSourceBoolean',
    

    to

    'source' => MagentoEavModelEntityAttributeSourceBoolean::class,
    

  2. $eavSetup = $this->eavSetupFactory->create([‘setup’ => $setup]);

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search