zend framework - Magento create nested categories programmatically and recursivelly -
is there way create nested categories using string like:
category 1/category 2/category 3/category 4/
a such of method me create them in easy way.
i have base method:
public function createcategories($categories, $parentid=2){ $arrcategories = explode("/", $categories); foreach($arrcategories $category){ $category = new mage_catalog_model_category(); $category->setname($category); $category->setisactive(1); $category->setdisplaymode('products'); $category->setisanchor(0); $parentcategory = mage::getmodel('catalog/category')->load($parentid); $category->setpath($parentcategory->getpath()); $category->save(); } }
but how create recursively function?
i have grouped them in array:
array(2) { [1] => array(3) { [0] => string(9) "ping pong" [1] => string(19) "accessori ping pong" [2] => string(13) "racchette nere" } [2] => array(3) { [0] => string(9) "ping pong" [1] => string(21) "ping pong accessories" [2] => string(11) "black rackets" } }
the id 1 , 2 store views id.
thanks
Comments
Post a Comment