Skip to content

How to create product attribute programmatically in Magento 2

Today, we will guide you on how to create a custom attribute for Products in Magento 2.
There are two ways to create the products attribute in Magento.

  • Manually : Go To admin >> Store >> Attributes >> Product
  • Programmatically

Add the below code to create an attribute for product using programmatically

Create text / textarea attribute

Create multi-select / dropdown attribute

For select option, We need to create Model file for define our status type of select box,
$statusType = ‘Dev/Testing/Model/Entity/Product/Attribute/Source/StatusType’;

We have create StatusType.php file under Model and define Status Type value.

Create StatusType.php file,
Path: app/code/Dev/Testing/Model/Entity/Product/Attribute/Source/StatusType.php

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Share via
Copy link
Powered by Social Snap