Demonstrate ability to use and customize Categories in Magento 2

Use and Customize Categories in Magento 2

Magento allows you to create multiple categories, assign different products to them, add CMS blocks to category pages, etc. 

Learn more at :

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.

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

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 (/).

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:

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

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:
    • 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

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 👍

Leave a Reply

Your email address will not be published. Required fields are marked *