When purchasing an item, there are many characteristics that a buyer considers, such as, size and color of a shirt. These specific characteristics of a product, are called, product attributes.
Creating them in Magento 2 is very simple, but let's get a better understanding of what an "Attribute" means.
What is an attribute?
An attribute basically is that element that defines the characteristics of a product. Besides that, attributesare also used as search parameters to filter the products themselves, in layered navigation.
The attribute, can be created either in the store menu, or on the product detail page, while you are creating the product itself.
How to Create a Product Attribute
To create an attribute, 5 Steps are required, let's see them in detail...
1. Create a new attribute
- Go to the Admin panel and follow the path Product -> Inventory ->Catalog. Now go to the Product Detail page and click on Add Attribute (Add Attribute)
- If you want to use an existing attribute, type the name of the attribute directly into the search bar and select it.
- If instead, you want to use a new one, click on the "NewAttribute" item.
Alternatively, you can also go to the New Attribute page, also by following this path: Shop ->Attributes ->Product and click on "Add New Attribute."
2. Complete Basic Properties
- In the "Default Label" field, enter the identifier of the 'attribute.
- In the "Catalog Input Type for Store Owner" section, select the input type to be entered for your attribute, from the list. For example, if it is the "color" attribute, you can select Dropdown or Multiple Choice. If it is other attributes, however, you can also select "Text Field" or other, depending on your needs.
- Should you choose the Multiple Choice or the menu Dropdown, you will have to add various options, like this:
- In the section "Manage Options" (Options Manager), click on Add Option (Add Option)
- At this point you will have to enter the name of the various values of the attribute. So if, for example, we are creating the "color" attribute, the values to be entered in Manage Options, are, for example, "Yellow", "Red" e "Green". If you want, you can enter simultaneously for the value written in the Admin box, different values for different store views when you have more than one.
Select "Is Default" if you want to use that particular value as the default.
- In the section "Manage Options" (Options Manager), click on Add Option (Add Option)
3. Complete Advanced Properties (Optional)
Completing this section, is not mandatory, but let's see how to do it anyway....
- First, enter the "AttributeCode," which must not contain spaces or more than 30 characters.
- In the "Scope" section, you can select whether to apply the attribute to Store View, Website or Global.
- If you put "Yes" under "UniqueValue," if you want the attribute value to be assigned to a specific product and only it.
- To perform a validity test of the data entered in the text field, set "InputValidationfor Store Owner" for some types of input you can enter validation of the entered value. For example, for "Text Field" section, only letters are allowed, different values will not be considered and we will be given error.
4. Label Title Management (labels)
- Open the "Manage Title" section.
- Enter the Label Title, and if you have multiple stores in multiple languages, you can also enter their translations.
5. Complete the Showcase Properties
Below you will find the section on Storefront Properties (Storefront Properties).
- Select "Yes" under "Usein Search" if you want the attribute to be available for search. By typing in the attribute value in the search, we will see all products with that attribute value among the results.
- To include the attribute in Product Comparison, select "Yes" in the "Comparable on Storefront" section.
- Then as for "dropdown," "multiple choice," and "price fields," follow the instructions below:
- Touse the attribute as a filter in layered navigation, set "Yes" in the "Use in Layered Navigation" section.
- To show the attribute in layered navigation on the search results page, you must set "Yes" in the "Use in Search Results Layered Navigation" section
- In the "Position" section, write the number for the position the attribute should have in the layered navigation menu
- To use the product attribute for promotional rules and conditions, select "Yes" in the "Use for Promo Rule Conditions" section
- For some input types, such as "Text Area," select "Yes" in "Allow HTML Tags to Frontend" , to have the text formatted with HTML. This setting also enables the WYSIWYG editor.
- To have the attribute also be visible on the Catalog page, select "Yes" under "Visible on Catalog Pages on Storefront"
- Then if your store supports a Product Listing, the attribute can appear in the Product Listing and be used as a kind of parameter. By configuring it under "Used in Product Listing" and Used for Sortin in Product Listing"
Once you have completed all these fields, all you have to do is save and you are done!