0
我想知道如何在magento 1.5xx中以編程方式創建新類別。此外,我需要在創建後返回類別ID。Magento 1.5x編程添加一個新類別並返回類別ID
我想知道如何在magento 1.5xx中以編程方式創建新類別。此外,我需要在創建後返回類別ID。Magento 1.5x編程添加一個新類別並返回類別ID
我在這裏寫了一篇完全錯誤的初始文章 - 在Google上找到答案並不容易!
總之,這裏的一些代碼,我使用的是在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();
有可以使用,以及(添加在管理面板中的類別時,他們關聯到表單域)其他屬性但不幸的是我沒有例子。網上有很好的帖子 - 我用它們來創造上述 - 但你可能需要通過Google深入挖掘才能找到它們。
我希望這會有所幫助,並且你沒有閱讀我的第一個答案,這沒有幫助。
乾杯, Zac