I am using below script to create product attribute with options.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$setup = $objectManager->get('Magento\Framework\Setup\ModuleDataSetupInterface');
$eav_setup_factory = $obj->get('Magento\Eav\Setup\EavSetupFactory');
$setup->startSetup();
$eavSetup = $eav_setup_factory->create(['setup' => $setup]);
// Product Attribute
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'customattribute',
[
'type' => 'int',
'label' => 'Custom Attribute Label',
'backend' => '',
'input' => 'select',
'wysiwyg_enabled' => false,
'source' => '',
'required' => false,
'filterable' => true,
'sort_order' => 3,
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL,
'group' => 'custom attribute group',
'used_in_product_listing' => true,
'visible_on_front' => true,
'option' => [
'values' => [
0 => 'Small',
1 => 'Medium',
2 => 'Large',
]
],
]
);
The options are not getting created with the above code. How can we create options?
The attribute is created once used the above code. Also, can we specify the attribute set to this code? by default, it is adding to the Default attribute set.
Can anybody help me with the above issue?