I use this method to create new categories:
private function createCat($name){
$category = Mage::getModel( 'catalog/category' );
$category->setStoreId( 0 );
$category->setName( $name );
$category->setUrlKey( strtolower($name) );
$category->setIsActive( 1 );
$category->setIsAnchor( 0 );
$category->setDisplayMode( 'PRODUCTS' );
$category->setPath( '1/3' );
$category->setPageTitle( $name );
$category->save();
return $category->getId();
}
After I know the identifier assigned by Magento to this category, I then call the following loop in a loop to assign each category a parent category:
private function assignCat($id, $parent){
$category = Mage::getModel( 'catalog/category' )->load($id);
$category->setPath( '1/3/'.$parent.'/'.$id );
$category->save();
return;
}
However, it does not work. The first method creates the categories perfectly, but after starting the second method I canβt even load the admin panel to show the categories.
What am I doing wrong?
EDIT:
. , catalog_category_entity, . - , , 0 . - , ?
: :
. , move() :
private function assignCat($id, $parent){
$category = Mage::getModel( 'catalog/category' )->load($id);
Mage::unregister('category');
Mage::unregister('current_category');
Mage::register('category', $category);
Mage::register('current_category', $category);
$category->move($parent);
return;
}