Skip to content
NewRedesigned blogFeedback
Jigar Karangiya

Demonstrate ability to use and customize Categories in Magento 2

This Magento 2 exam note demonstrates to create and manage categories,what is parent_id 0,Category hierarchy tree structure implementation.

Demonstrate ability to use and customize Categories in Magento 2
Written by
JKJigar Karangiya
Published
Reading time
2 min read

Jigar Karangiya · · 2 min read

(opens in new tab)Magento allows you to create multiple categories, assign different products to them, add CMS blocks to category pages, etc.

Learn more at : https://experienceleague.adobe.com/en/docs/commerce-admin/catalog/categories/categories (opens in new tab)

Category Hierarchy Tree Structure in Magento 2

Describe the category hierarchy tree structure implementation

Magento 2 categories are presented in the form of a tree and can have any nesting.

Figure 01

Let’s see & understand the catalog_category_entity table structure, where the information about categories structure is stored.

Figure 02

The main columns are below for category structure:

entity_id – the category ID.

parent_id – parent category ID.

path – path to the category in the categories tree. This is a record with a path to the category in the categories tree. Represents a record in the form of a sequential arrangement of entity_id categories, separated by a slash (/).

Figure 03

The construction of the category tree begins with an entry with the parent_id = 0 value. This entry has a value of entity_id = 1. Categories whose parent_id = 1 act as Root Categories. And then the construction of the category tree is implemented through the connection parent_id <—> entity_id

To avoid recursive parent-child traversing, flat category path is saved for every category. It includes all parents IDs. This allows to optimize children search with single query. E.g. to search children of category id 2 and knowing its path ‘1/2’, we can get children:

Figure 04

Also, Please refer below ER Diagram which show EAV Relationship of the catalog_category_entity table.

Figure 05

What is the meaning of parent_id 0?

Magento\Catalog\Model\Category constants:

  • ROOT_CATEGORY_ID = 0 — looks like some reserved functionality, has only one child
  • TREE_ROOT_ID = 1 — all store group root categories are assigned to this node
  • These categories are not visible in admin panel in category management.
  • When creating root category from admin, parent_id is always TREE_ROOT_ID = 1.
  • Magento\Store\Model\Store::getRootCategoryId (opens in new tab):
    • TREE_ROOT_ID = 1 when store group is not selected
    • store group root category ID
  • Store group root category allows only selecting from categories with parent_id = TREE_ROOT_ID = 1 (opens in new tab)

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 by which the category will be displayed in the browser.

I hope this article helped you to find what you were looking for.

Bookmark it for your future reference. Do comment below if you have any other questions on that.

Do share this article with your team.

You may also like,

Which refund types are available, and how are they used?

Happy Reading & Best of luck for the exam 👍

Keep reading
All posts

01 · 2 min · Shares Adobe Commerce Core, Quick Notes

Magento 2 UI Components and Visibility Conditions

Have you ever wanted to show or hide certain parts of your Magento store based on specific conditions? For example, showing special offers only to VIP customers or displaying different content in different store views?

2 min

02 · 3 min · Shares Adobe Commerce Core, Quick Notes

Deep Dive into Magento 2 Events and Observers

In this tutorial, I will guide you through the popular events and observers which works based on event driven architecture which is also referred as publish-subscribe pattern.

3 min

03 · 2 min · Shares Adobe Commerce Core, Quick Notes

How to Remove Sample Data from Magento 2

Discover the step-by-step process of removing sample data from your Magento 2 installation in my latest blog post. I’ll guide you through accessing your server, navigating to the Magento 2 directory, and using Magento’s command-line tool to remove sample data.

2 min

Newsletter

New Magento tutorials, straight to your inbox

Code examples, performance tips, and fixes for common Magento issues. No spam.

Subscribe