How to get all Root Categories ids in Magento 2?

If your Website is setup with multiple store and each store has different Root Category assigned, In that case you need to refer below blog for getting all root category ids by programmatically.

Let’s consider your store with Two Root Category available.

First Native Magento Default Category which id is 2.
Second, create custom Root Category based on your requirement which id is 42.

Now How to get above root category id using coding in Magento 2, You can get root category id by below way,

Call from template file,

Output as array,

In above case 1 is for Root Catalog id,
2 is your Default Category id.
42 is your custom created root category id.

Let’s explore get category collection per store by,
Get Category Collection of specific store

 

One Reply to “How to get all Root Categories ids in Magento 2?”

Leave a Reply

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