php - Adding new categories and subcategories - Magento -
what need add new categories , subcategories .csv file. can create new root category, don't know how make subcategory:
$category = mage::getmodel('catalog/category'); $category->setstoreid(0); $rootcategory['name'] = 'reserved'; $rootcategory['path'] = "1"; // root category $rootcategory['display_mode'] = "products_and_page"; $rootcategory['is_active'] = 1; $category->adddata($rootcategory); $parentcategory= $category; // doesn't work, want here (root) category id try { $category->save(); } catch (exception $e){ echo $e->getmessage(); }
csv file formatted this:
root_cat_id;subcat_id;subcat_name;subsubcat_id;subsubcat_name; ex. 1;2;animal;3;dog;
how can id of added category, , add subcategory related category?
thanks in advance
to make category child of category, set path parent categories path before saving it.
$childcategory->setpath($parentcategory->getpath())
after child category saved (and has id), id appended path attribute automatically after save()
called.
magento automatically set parent_id , level attributes you.
Comments
Post a Comment