2014-02-11 57 views
0

我正在創建一個新的類別形式前端編程..每當我運行此腳本比新的類別創建,但它不能設置爲活動。所以它不能出現在頂部菜單上。Pondemetically設置類別,以啓用在magento

我的代碼是: -

$parentId = '2';  
    $category = new Mage_Catalog_Model_Category(); 
    $category->setName('abc'); 
    $category->setUrlKey('abc'); 
    $category->setIsActive(1); 
    $category->setDisplayMode('PRODUCTS'); 
    $category->setIsAnchor(1); 
    $parentCategory = Mage::getModel('catalog/category')->load($parentId); 
    $category->setPath($parentCategory->getPath());    
    $category->save(); 
    unset($category); 

不能設置$分類 - > setIsActive(1);請建議我在哪裏做了一些更改以將其設置爲啓用。

+0

如果您發現我的答案有幫助,然後接受我的答案 –

回答

0

您可以選擇存儲的ID分配給類別

$parentId = '2';  
     $category = new Mage_Catalog_Model_Category(); 
     $category->setName('abc'); 
    $category->setStoreId(0); // you have top set your store id to active category 
     $category->setUrlKey('abc'); 
     $category->setIsActive(1); 
     $category->setDisplayMode('PRODUCTS'); 
     $category->setIsAnchor(1); 
     $parentCategory = Mage::getModel('catalog/category')->load($parentId); 
     $category->setPath($parentCategory->getPath());    
     $category->save(); 
     unset($category); 
0
$categoryName = abc; // Name of Category 

    // Create category object 
    $category = Mage::getModel('catalog/category'); 
    $category->setStoreId(0); // No store is assigned to this category 

    $rootCategory['name'] = $categoryName; 
    $rootCategory['path'] = "1/2"; // this is the catgeory path - 1 for root category 
    $rootCategory['display_mode'] = "PRODUCTS"; 
    $rootCategory['is_active'] = 1; 

    $category->addData($rootCategory); 

    try { 
    echo'<pre>'; 
    print_r($category); 
    $category->save(); 
    $rootCategoryId = $category->getId(); 
    } 
    catch (Exception $e){ 
    echo $e->getMessage(); 
    } 

我認爲問題的路徑在你的代碼,試試吧,如果有比讓我知道的任何問題。