cancel
Showing results for 
Search instead for 
Did you mean: 

function for adding attributes

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

function for adding attributes

I am downloading a list of Attributes from another source and want to add the in bulk, can I modify the below code to do this

 

    {
        $eavSetup = $this->eavSetupFactory->create();
        $eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY,
            'clothing_material',
            [
                'group' => 'General',
                'type' => 'varchar',
                'label' => 'Clothing Material',
                'input' => 'select',
                'source' => 'Connectortech\Attributes\Model\Attribute\Source\Material',
                'frontend' => 'Connectortech\Attributes\Model\Attribute\Frontend\Material',
                'backend' => 'Connectortech\Attributes\Model\Attribute\Backend\Material',
                '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
            ]
        );
    }

 

I believe I would need to make it a function?

What dependencies do I need to declare?

How would I call it with arguments for Attribute Name and Label?

Could I also pass an array or Json for the Source? or do I need to create a file for each attribute?