konika
konika

Reputation: 113

Custom product attribute not showing in admin catalog section magento 2.1

I have added custom product attribute in Magento 2.1 and that product is showing in attribute section but couldn't be shown in magento catalog section where we have created products

Below are the code which I am using to create attribute.

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

    /**
     * Add attributes to the eav/attribute
     */

    $eavSetup->addAttribute(
        \Magento\Catalog\Model\Product::ENTITY,
        'test_author',
        [
            'type' => 'int',
            'backend' => '',
            'frontend' => '',
            'label' => 'Test Author',
            'input' => '',
            'class' => '',
            'source' => '',
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
            'visible' => true,
            'required' => false,
            'user_defined' => false,
            'default' => 0,
            'searchable' => true,
            'filterable' => true,
            'comparable' => false,
            'visible_on_front' => true,
            'used_in_product_listing' => true,
            'unique' => false,
            'apply_to' => ''
        ]
    );

enter image description here

Upvotes: 0

Views: 4246

Answers (1)

Swapna Taru
Swapna Taru

Reputation: 688

You can try the following code -

/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
/**
* Add attributes to the eav/attribute
*/
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'test_author',
[
'group' => 'General',
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Test Author',
'input' => 'textarea',
'class' => '',
'source' => '',
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
'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' => 'simple,configurable,virtual,bundle,downloadable'
]
);

Upvotes: 1

Related Questions