- 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.
- Deploying Node.js
- Cocos2D-X權威指南(第2版)
- CouchDB and PHP Web Development Beginner’s Guide
- 重學Java設計模式
- 零基礎學Python數據分析(升級版)
- 精通Linux(第2版)
- JavaCAPS基礎、應用與案例
- 利用Python進行數據分析
- Qt5 C++ GUI Programming Cookbook
- BeagleBone Robotic Projects(Second Edition)
- Emotional Intelligence for IT Professionals
- Practical GIS
- 每個人的Python:數學、算法和游戲編程訓練營
- Python 3.6從入門到精通(視頻教學版)
- JavaScript程序設計基礎教程(慕課版)