In order to create new product attribute in Magento 2 take the following steps:
1. Go to Admin Panel > Stores > Attributes > Product.
2. Press the Add New Attribute button.
3. Fill out the Attribute Properties section.
- Enter a Default Label of an attribute. It will be displayed on the admin panel.
- Choose a type of an attribute in the Catalog Input Type for Store Owner field. There are such available values here as: Text Field, Text Area, Date, Yes/No, Mutliple Select, Dropdown, Price, Media Image, Fixed Product Tax, Visual Swatch,Text Swatch.
- Select yes in Values Required field in order to make the attribute required for products. In this case, you won't be able to save the product with this attribute if you don't set its value.
4. Fill out the Advanced Attribute Properties section.
- Set the Attribute Code. If you leave this field empty, the attribute code will automatically be generated from the default label.
- In Scope you choose a level the attribute will be edited on. As far as Magento 2 is a multilingual and multi-website platform it is better if it is the text field attribute to leave it on a Store view level. In case attribute value doesn't depend on site or language it will be wiser to choose Global.
- Set a Default Value of an attribute. We pay your attention to the fact default value won't be automatically set all existing products. It will be added only after the resaving of product.
- In the Unique Value field set Yes, if you don't want the same attribute value to be applied to different products, e.g. SKU attribute should be unique.
5. In Input Validation for Store Owner select box set filter that will be used before saving a product to validate an attribute value.
6. Filter Yes in the Add to Column Options field in order to add the attribute to the list of column options in the product grid.
7. Choose Yes in Use in Filter Options field if you want this attribute to be used while filtering products.
8. Set a Default Store View which will be displayed of the Storefront in Manage Labels section. In case you have a multilingual site, you can set a label for each language.
9. Configure the Storefront Properties.
- If you want the attribute to be used while search, choose Yes in the Use in Search field.
- In the Comparable on Storefront field you can select whether this attribute will be used on compare product page.
- In Used in Layered Navigation you choose the attribute to be used in layered navigation.
- You choose whether the attribute will be used in layered navigation search in the Use in Search Results Layered Navigation.
- In the Position field, you set the position of the attribute in the layered navigation.
- Choose Yes in the Use for Promo Rule Conditions field if you want this attribute to be used in rule conditions for cart price rules and catalog price rule as well.
- In order to make the attribute displayed on a product page in additional options, choose Yes in the Visible on Catalog Pages on Storefront field.
- Choose Yes in Use in Product Listing to add this attribute value to the PHP product object in a product list (product collection).
- If you want the attribute to be used for the sorting process choose Yes in the Used for Sorting in Product Listing field.
Once you have finished don't forget to press the Save Attribute button.
Assign to Attribute Set
Afterwards, go to Admin Panel > Stores > Attributes > Attribute Set, choose the attribute you need, drag and drop it from the Unassigned Attributes to Groups.
Once you have finished don't forget to save the attribute set.