Add category attribute Programmatically in Magento 2.

We can create custom category attribute programmatically in Magento 2 using simple module. In our demo we have created a simple text field attribute for a category.

You can see a category attribute in the backend using Catalog -> Categories Page.
Click on Any category and you can see our custom attribute in General Section after the category name.

Continue reading “Add category attribute Programmatically in Magento 2.”

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