- Magento 2 Development Cookbook
- Bart Delvaux
- 621字
- 2021-07-30 09:46:22
Working with attribute sets
Magento has a flexible system to work with products. When you sell, for example, a board game or a computer, the specifications of each product are different. For a board game, information such as age and duration is relevant. For a computer, a lot of technical specifications are relevant, such as the CPU power, disc size, and so on.
To cover this, Magento 2 comes with a system called product templates, which can be compared with attribute sets in Magento 1.
A product template is a specification of product attributes that you can assign to products.
Getting ready
In the backend, we will use the pages Stores | Attributes | Product and Stores | Attributes | Attribute Set.
We will create a newproduct
attribute and a new product template (such as an attribute set) that we can use in new products.
How to do it
In the following steps, we will create an extra product attribute that we can use in a product template:
- Navigate to Stores | Attributes | Product in the backend, and click on the Add New Attribute button.
- Populate the form with the following instructions:
- Default label:
Available from
(This label will be used to identify the attribute) - Catalog Input Type for Store Owner:
Date
(this is the type of the attribute)
- Default label:
- Click on Save and Continue Edit and the attribute will be saved. You will see that the Attribute Code field is prepopulated with a code that is generated from the label.
- Additionally, we can set the following values:
- Values required:
No
- Scope:
Store View
(with this setting, we create the possibility to specify separate values for each store view) - Default value: Leave this field empty
- Unique value:
No
- Values required:
- In the Manage Labels tab, we can set the label that will be displayed on the product detail page. If left empty, the attribute label will be used.
- In the Storefront Properties tab, we can set the following properties:
- Use in search:
No
- Comparable on Storefront:
No
- Use for Promo Rule Conditions:
No
- Allow HTML Tags on frontend:
No
- Visible on Catalog Pages on Storefront:
No
- Used in Product Listing:
No
- Used for Sorting in Product Listing:
No
- Use in search:
- Click on Save Attribute; this will save the attribute.
- The next step is to create an Attribute Set to which will assign a product to. In the backend, navigate to Stores | Attributes | Attribute Set.
- Click on the Add Attribute Set button and fill in the form, as follows:
- Clicking on Save will open the overview page.
- Create a group named Game specific data and drag the available_from and manufacturer attributes to it. The overview will look as follows:
- Save the Attribute Set.
- Navigate to Product | Catalog and create a new product by clicking on the New Product button.
- Select the right Attribute Set in the form, as shown in the following screenshot:
- When selecting the product template, you will see that the Game specific data tab appears in the product tab, as shown in the following screenshot:
How it works
Product attributes and Attribute Sets are used when you work with multiple families of products. In the sample data of our shop, there are more attribute sets available for bags, clothing, and more.
With Attribute Sets, you can make groups of attributes for every product family. When creating a product attribute, you have to choose the type of the attribute, which can be one of the following:
- Text field
- Text area
- Date
- Yes/No
- Multiple select
- Dropdown
- Price
- Media image
- Fixed Product Tax
Tip
When you want to use an attribute as a filter in the left navigation on the category pages, this attribute must have the type Dropdown, Multiple Select or Price.
- DevOps Automation Cookbook
- 小程序開發原理與實戰
- Java EE 7 Performance Tuning and Optimization
- SQL Server 2016數據庫應用與開發
- HTML5+CSS3 Web前端開發技術(第2版)
- Android嵌入式系統程序開發:基于Cortex-A8(第2版)
- .NET 4.5 Parallel Extensions Cookbook
- JSP程序設計實例教程(第2版)
- 跟戴銘學iOS編程:理順核心知識點
- Android Sensor Programming By Example
- Python數據科學實踐指南
- Python高性能編程(第2版)
- 信息學奧林匹克競賽初賽精講精練
- Mastering JavaScript Promises
- Cinder:Begin Creative Coding