Magento以编程和递归方式创建嵌套类别

Magento以编程和递归方式创建嵌套类别,magento,zend-framework,Magento,Zend Framework,有没有一种方法可以使用以下字符串创建嵌套类别: Category 1/Category 2/Category 3/Category 4/ 一个这样的方法,帮助我以简单的方式创建它们 我有基本方法: public function createCategories($categories, $parentId=2){ $arrcategories = explode("/", $categories); foreach($arrcategories as $category)

有没有一种方法可以使用以下字符串创建嵌套类别:

Category 1/Category 2/Category 3/Category 4/
一个这样的方法,帮助我以简单的方式创建它们

我有基本方法:

public function createCategories($categories, $parentId=2){

    $arrcategories = explode("/", $categories);

    foreach($arrcategories as $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();
    }
}
但是如何创建递归函数呢

我已将它们分组在此阵列中:

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"
  }
}
ID 1和2是商店视图ID。

谢谢