2013-11-26 9 views
0

你好,我剛開始學習magento。現在我試圖通過腳本在magento中導入類別。通過腳本在magento中導入類別

我的Magento的代碼看起來像

<?php 
    require_once 'businessclasses.php'; 
    define('MAGENTO', realpath(dirname(__FILE__))); 
    require_once MAGENTO . '/app/Mage.php'; 
    umask(0); 
    $count = 0; 

    echo "<pre>"; 
    $data= new getCSV(); 
    $rows=$data->getRootCategories(); // Gets the list of root categories. 

    foreach($rows as $row) { 
     echo $categoryName = $row['d']; // Name of Category 

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

     $rootCategory['name'] = $categoryName; 
     $rootCategory['path'] = "23/25"; // this is the catgeory path 
     $rootCategory['display_mode'] = "PRODUCTS"; 
     $rootCategory['is_active'] = 1; 
     $category->addData($rootCategory); 

     try { 
      $category->save(); 
      echo $rootCategoryId = $category->getId(); 
     } 
     catch (Exception $e){ 
      echo $e->getMessage(); 
     } 
    } 
?> 

此代碼運行沒有錯誤,也該線

echo $rootCategoryId = $category->getId(); 

打印唯一的ID爲每個類別(環路),但是當我看到在管理潘內爾它沒有顯示任何東西。像沒有進口的類別。

我已經回答了這個 Question.但它沒有幫助。

任何幫助,將不勝感激。謝謝。

回答

1

嘿傢伙,我得到了答案。

$rootCategory['path'] = "1/23/25"; // this is the catgeory path <-- I was giving this path wrong. 
1

那麼你已經得到了你自己的答案。但是,如果有人正在尋找類別和產品以及其他導入/導出的其他工具,我建議Magmi http://sourceforge.net/projects/magmi/,真棒工具爲我節省了很多時間。