I want to add multiple attribute on one go

by avesh   Last Updated June 21, 2018 12:09 PM

How can i add multiple attributes in one script.

namespace Backadmin\Grid\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 CategorySetupFactory $categorySetupFactory
     */
    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,
            'clothing_material',
            [
                'group' => 'General',
                'type' => 'varchar',
                'label' => 'Clothing Material',
                'input' => 'text',
                'source' => '',
                '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
            ]
        );
    }

}


Answers 1


Magento2 -> Create Multiselect Product Attribute Programmatically
['code' => 'code_of_the_attribute', 'attribute_set' => '*', 'label' => 'Concern', 'attribute_group' => 'Extra Content', 'type' => 'text', 'input' => 'multiselect', 'option' => ['values' => [ 'Option 1', 'Option 2', 'Option 3', ], ], 'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend', 'unit' => '', 'required' => false, 'visible' => true, 'visible_on_front' => false, 'sort_order' => 2, 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE, 'searchable' => true, 'filterable' => true, 'used_for_promo_rule' => true, 'comparable' => false, 'wysiwyg_enabled' => false, 'used_in_product_listing' => false, 'used_for_sort_by' => false, ]

Jugal Kishor
Jugal Kishor
June 21, 2018 11:28 AM

Related Questions



Merging Options

Updated May 16, 2015 21:04 PM