In the first part of “How To Create a Theme in Magento 2” we were talking about theme declaration, registration, applying in the admin panel and Composer.json file addition. Now it’s time to continue.
We continue exploring the mechanism of EAV data storage in Magento 2. In this article, we will cover Magento 2 attribute types and how they are presented in the admin. In the 2nd part, we will talk about the role of attribute sets and attribute groups.
How are attributes presented in the admin
Attributes are the name (Label) + field, the value of which can be changed by the administrator.
The following attribute properties affect its display:
- frontend_model is a class that describes the display of the field on the front end section of the site. It’s inherited from Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend and overrides the getValue method to change the output values of the attribute
- frontend_input – the form element that is displayed in the admin section of the site
- frontend_label – the name of the attribute that is displayed in the admin section of the site. It is also displayed on the frontend section of the site unless another value is specified in the eav_attribute_label table (in the attribute settings it is changed on the “Manage Labels” tab)
- frontend_class is used to validate the attribute value in the admin section of the site. In the attribute settings, the property is called Input Validation for Store Owner. For the e-mail validation, the frontend_class property has the value “validate-email”.
Magento has the following standard attribute types:
It is represented as a text input
It is represented as a multi-line field. It is possible to turn on the WYSIWYG editor in its attribute settings.
It appears as a text field for entering dates and a drop-down calendar.
It is represented in the form of a switch that has 2 positions: Yes and No
It is presented in the form of a list that suggests choosing several values, including none.
It is represented in the form of a drop-down list that suggests choosing only one value.
It appears in the form of a drop-down list.
Media Image is represented differently than other fields. There is no field for Media Image. An attribute of the Media Image type adds a role to an image and a video of the product.
Fixed Product Tax
Allows changing taxes for countries and their states. It is presented in the form of a table with a country and a state and the corresponding tax.
Visual Swatch is presented to the administrator the same way as the Dropdown. To a user, it is presented in the form of buttons, filled with color, or containing a picture. The field is convenient to use in Configurable products, for example, for color selection.
It is similar to Visual Swatch, only the contents of the button is text.
The role of attribute sets and attribute groups
An attribute set is needed in order to display different attributes when editing different types of products (like shoes and clothing). For example, we have the shoe_size and clothing_size attributes. For footwear, you need to display the shoe_size attribute, for clothes — clothing_size. Attribute set allows hiding unnecessary attributes, displaying the necessary ones, changing the sorting and grouping. Groups are needed for the convenience of filling the products by an administrator. They have no effect on the logic of loading / storing the products.
Below you can see the Design and Schedule Design Update folders, which are attribute groups. The nested elements are attributes.
Attributes in the product:
That’s it for part 3. The series is to be continued with part 4, in which we will cover additional options when saving EAV entities and customizations based on changes to attribute values.