Php Magento 1.5x以编程方式添加新类别并返回类别ID

Php Magento 1.5x以编程方式添加新类别并返回类别ID,php,magento,Php,Magento,我想知道如何在magento 1.5xx中以编程方式创建新类别。此外,我还需要在创建类别ID后将其返回。我在这里写了一篇完全错误的初始帖子-在谷歌上找到这个问题的答案并不容易 无论如何,这里有一些我在Magento 1.5.0.1中使用的代码 -- The parent category you want to work with. $parentCategory = $this->getParentCategory(); -- This method needs to refer to

我想知道如何在magento 1.5xx中以编程方式创建新类别。此外,我还需要在创建类别ID后将其返回。

我在这里写了一篇完全错误的初始帖子-在谷歌上找到这个问题的答案并不容易

无论如何,这里有一些我在Magento 1.5.0.1中使用的代码

-- The parent category you want to work with.
$parentCategory = $this->getParentCategory(); 
-- This method needs to refer to the static block you want to display if you're using one.
$categoryBlockId = $this->getCategoryBlockId(); 

$category = Mage::getModel( 'catalog/category' );
$category->setStoreId( $storeId );
$category->setName( $categoryName ); -- The name of the category
$category->setUrlKey( $categoryUrlkey ); -- The category's URL identifier
$category->setIsActive( 1 ); -- Is it enabled?
$category->setIsAnchor( 0 ); -- I think this relates to whether it shows in navigation.
-- Display mode can be 'PRODUCTS_AND_PAGE', 'PAGE', or (I think) 'PRODUCTS'
$category->setDisplayMode( $displayMode ); 
$category->setPath( $parentCategory->getPath() ); -- Important you get this right.
-- This is required if DisplayMode is 'PRODUCTS_AND_PAGE' or 'PAGE'.
$category->setLandingPage( $categoryBlockId ); 
$category->setPageTitle( 'Your Page Title' );
$category->save()

$categoryId = $category->getId();
您还可以使用其他属性(在“管理”面板中添加类别时,它们与表单字段相关),但遗憾的是,我没有这些属性的示例。网上有很多不错的帖子——我用它们来创建上面的帖子——但你可能需要通过谷歌深入挖掘才能找到它们

我希望这会有帮助,而且你没有读到我的第一个答案,这也不会有帮助

干杯, 扎克