I want to create programatically a category in my data folder of my module. The Flat categories option is enabled.
When a I try to create a category like so:
$category
->setStoreId(0)
->setName('My category')
->setUrlKey('club-campaigns')
->setPath($rootCategory->getPath())
->setIsActive(1)
->setIsAnchor(1)
->setIncludeInMenu(1)
->addData($data)
->setCustomDesignApply(1)
->save();
I get an error which says that catalog_category_flat doesn't exists. Ok, so I know that flat categories info is kept in catalog_category_flat_store_storenumber table. I looked in the database and I have the following tables:
catalog_category_flat_store_1
catalog_category_flat_store_2
catalog_category_flat_store_3
catalog_category_flat_store_4
catalog_category_flat_store_5
catalog_category_flat_store_6
and I want to create a category for store 6. Good, now if I do like this:
$category
->setStoreId(6)
->setName('My category')
->setUrlKey('club-campaigns')
->setPath($rootCategory->getPath())
->setIsActive(1)
->setIsAnchor(1)
->setIncludeInMenu(1)
->addData($data)
->setCustomDesignApply(1)
->save();
the category is created without errors, and it sets the info in catalog_category_flat_store_6 but if I go to admin>Manage Categories and cant't see my category created.
I think that when I create a category I should set te store id of the admin(0) so I can see it in the admin panel but then I get the error above, and if I create with store 6 I don't see it in the admin. I'm really stuck.
How can I properly create my category programatically without problems?