Skip to main content
added 76 characters in body
Source Link
Mohit Patel
  • 4k
  • 4
  • 24
  • 53

There are four major steps to create custom product attributes programmatically:

1: Create the Setup File InstallData.php

    <?php
namespace Company\Mymodule\Setup;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface
{
 private $eavSetupFactory;

 public function __construct(EavSetupFactory $eavSetupFactory)
 {
 $this->eavSetupFactory = $eavSetupFactory;
 }
 
}

namespace Company\Mymodule\Setup;

use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface { private $eavSetupFactory;

public function __construct(EavSetupFactory $eavSetupFactory) { $this->eavSetupFactory = $eavSetupFactory; }

}

2: Define the install() Method

3: Create Product Attribute

4: Upgrade

For more details, visit this blog:

Magento 2 Add Product Attribute Programmatically

There are four major steps to create custom product attributes programmatically:

1: Create the Setup File InstallData.php

<?php

namespace Company\Mymodule\Setup;

use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface { private $eavSetupFactory;

public function __construct(EavSetupFactory $eavSetupFactory) { $this->eavSetupFactory = $eavSetupFactory; }

}

2: Define the install() Method

3: Create Product Attribute

4: Upgrade

For more details, visit this blog:

Magento 2 Add Product Attribute Programmatically

There are four major steps to create custom product attributes programmatically:

1: Create the Setup File InstallData.php

    <?php
namespace Company\Mymodule\Setup;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface
{
 private $eavSetupFactory;

 public function __construct(EavSetupFactory $eavSetupFactory)
 {
 $this->eavSetupFactory = $eavSetupFactory;
 }
 
}

2: Define the install() Method

3: Create Product Attribute

4: Upgrade

For more details, visit this blog:

Magento 2 Add Product Attribute Programmatically

Source Link

There are four major steps to create custom product attributes programmatically:

1: Create the Setup File InstallData.php

<?php

namespace Company\Mymodule\Setup;

use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface { private $eavSetupFactory;

public function __construct(EavSetupFactory $eavSetupFactory) { $this->eavSetupFactory = $eavSetupFactory; }

}

2: Define the install() Method

3: Create Product Attribute

4: Upgrade

For more details, visit this blog:

Magento 2 Add Product Attribute Programmatically