In this article we will take a look at another topic from Magento 2 front end developer certification — using and customizing categories in Magento 2. We will take a look at such points of these topic, as creating and managing categories, category hierarchy, the construction of paths, attribute values for displaying a new category in the store and strategies for organizing products into categories.
Category properties and features
The categories in Magento 2 are designed to more conveniently organize the display of products and their grouping. The categories are also used to build the top menu. They have their own settings. To edit them, go to the Catalog ➜ Categories page and select a category to edit.
Of all the settings, you can select the main ones:
Enable Category — enables or disables category display on the frontend.
Include in Menu — determines if this category will be enabled in the top menu.
The next tab is Display Settings
Display mode allows you to switch the category display mode. There can be three modes:
- Products only. The page of this category will only display the description of the category and products.
- Static block only. Only the description and the static block that was selected in the Tab Content above will be displayed. Products will not be displayed
- Static block and Products. Both of the abovementioned blocks will be displayed.
Anchor determines whether layered navigation will be displayed in this category.
Magento Webdesign
Take your online store to the next level with BelVG Magento Webdesign
Visit the pageTabs with the settings of Search Engine Optimization and Products in Category are intuitive. The first allows you to add meta descriptions for categories, the second allows you to add products that will be displayed in this category.
The Design and Schedule Design Update Tabs
Here you can set whether the theme of the parent category will be used (the Use Parent Category Settings parameter). You can also choose which of the themes or which type of layout will be used in this category (Theme and Layout).
Layout Update Xml is used for adding xml instructions through the administrator interface.
Schedule Update From allows you to specify the period during which the changes to the Design settings will apply for this category.
How to create and manage categories
To create a category you need to go to Catalog ➜ Categories
Choose what type of category you need to create: Root Category or Subcategory
Add Root Category creates a new category in the root of the categories tree. In future, the root directory will be used when setting up a multistore.
Add Subcategory creates a subcategory in the active (selected in the tree) category.
Implementing the category hierarchy tree structure (the internal structure inside the database). How are paths constructed
Categories in Magento 2 are stored as a tree and can have any nesting.
To implement the category tree in Magento 2, use the following logic. The image below shows the catalog_category_entity table structure. It stores the information about the category structure.
Here are the main columns that are responsible for the structure of the category:
entity_id is the category identification itself;
parent_id is the id of the parent category;
path is the path to the category in the category tree. It represents the entry as a sequential arrangement of entity_id categories, separated by a slash (/).
The construction of a category tree starts with a record which has the value of parent_id = 0. This record has the value of entity_id = 1. Categories with parent_id = 1 act as Root Categories. After that, the construction of the category tree occurs via the parent_id <—> entity_id relationship.
Which attribute values are required to display a new category in the store
When creating a category, the only required value is Category name. Based on this name, the URL Key is automatically generated, which is the path at which the category will be displayed in a browser.
Strategies for organizing products into categories
In most cases, the strategy of organizing products by category depends on the specifics of the business presented in the webshop.
One of the options for organizing products is to divide products into categories depending on the used attributes attribute sets. That means, that the products with the same set of additional attributes will be rendered into separate categories. This will allow you to get a more intuitive product filter (layered navigation), for example, there will be no filter by sizes of T-shirts in the bicycle section. Further, the separation of products can be made depending on the attribute values and the target group of buyers (children, adults, men, women).
But in most cases, the structure and organization of products is what marketing departments deal with.
Thank you for reading, I hope this was useful and will help you to get ready for the certification exam.
Keep track of the unregistered users with this free Magento Guests Catalog extension.