1

有没有办法使用如下字符串创建嵌套类别:

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。

谢谢

4

0 回答 0