Everyone knows there are admin interface to create categories, but if you want to create a category programmatically. Using Magento’s catalog/category model we can create a Magento category via a program. You have to set category title and Url key in order to show in the frontend.
Magento creates category programmatically
Here I’ve attached the PHP code for creating a category programmatically. You can write this in any controller or a PHP file that calls Magento’s bootstrapper. In the below example we are creating a category under a parent category 1
Note: You should have a parent category in order to create category,
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.
Leave a Reply