有没有办法使用如下字符串创建嵌套类别:
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。
感谢