2016-01-06 16 views
0

我的問題是在導入我的數據時得到正確的菜單結構。在單個產品上導入多個類別

我使用的Magento 1.9.2.2

我收到我的數據以CSV格式是這樣的:

"sku","Cat1","Cat2","Cat3","Cat4" 
"001","Plumbing","Pressfittings & pipes","Unipipe - MLC","Clutch" 
"002","Tools","Handtools|Pipetools","Pipetools|Pipecutters & Scissors","Plastic scissors" 
"003","Tools|Plumbing","Handtools|Pipetools|Pipes & Fittings","Pipetools|Calibration|Alupex fittings & tubes","Calibration tools|Tools for alupex" 

我做了一個小程序來除掉那些「|」和什麼來後,使:

"002","Tools","Handtools|Pipetools","Pipetools|Pipecutters & Scissors","Plastic scissors" 

變爲:

"002","Tools","Handtools","Pipetools","Plastic scissors" 

但我很想創建所有的墊層類別,所以我也得到這個SKU的002:

"002","Tools","Pipetools","Pipecutters & Scissors","Plastic scissors" 

我相信Magento會以某種方式使用該結構,但我很難弄清楚如何導入它。

我已經嘗試了手動創建類別後正常導入Magento,並且這不起作用。 我也嘗試用Magmi創建它們,但是我無法讓Magmi使用多個主要和子類別。

有沒有人看到這種數據格式,並有正確的方向線索,如何讓它導入到菜單結構?

我有2500個主要和子類別在一起,所以手動創建它們根本不會工作。

想法,問題或意見,歡迎! :)

回答

0

MAGMI'飛行類別進口商'一定會爲你做這個。我建議您非常仔細地閱讀MAGMI wiki上的說明:您需要的所有信息都在那裏,但我經常發現必須仔細檢查並重新閱讀MAGMI wiki上的詳細信息和示例。

MAGMI下載說明安裝和運行:http://wiki.magmi.org/index.php?title=Main_Page#Download_and_Install_Magmi

對即時類進口商MAGMI說明:http://wiki.magmi.org/index.php?title=On_the_fly_category_creator/importer

如果你還沒有使用MAGMI之前然後用一個簡單的CSV開始一起工作確保您的安裝設置正確,並且您可以導入創建簡單產品的csv。

我認爲您面臨的主要挑戰是將您問題中描述的CSV文件格式轉換爲MAGMI可以使用的CSV格式。或者,您可以在MAGMI中編寫代碼來轉換CSV數據,但如果這是一次性過程,我認爲這可能過於複雜。

我不知道,我按照你的CSV例子的語法,但如果第一個字符串始終是頂級類別,然後在管道符號代表「子類別遵循」然後

"003","Tools|Plumbing","Handtools|Pipetools|Pipes & Fittings","Pipetools|Calibration|Alupex fittings & tubes","Calibration tools|Tools for alupex"

你爭取作出MAGMI CSV這樣

"sku","categories" "003","Tools::1::1::1/Plumbing::1::0::1;;Handtools::1::1::1/Pipetools::1::0::1/Pipes & Fittings::1::0::1;;Pipetools::1::1::1/Calibration::1::0::1/Alupex fittings & tubes::1::0::1;;Calibration tools::1::1::1/Tools for alupex::1::0::1"

晦澀::1::1::1表示is_activeis_anchorinclude_in_menu分別可以省略。

這不關我的事,但我深切關注由子類別標籤的兩個空間'Tools for alupex'(不啓動我的小寫Alupex或AluPEX)

+0

感謝馬拉奇,這是幫助解決方案我。我的分類有點搞砸了,所以在重新安排和閱讀你提供的鏈接後,Magmi完美地完成了這個訣竅。 – bjarkemonsted

0

你必須以編程方式創建這些類別,不可能通過導入(也許通過magmi但我不知道)。將腳本放入您的magento根目錄並運行它。這是你可以如何繼續(需要拋光):

$category = Mage::getModel('catalog/category'); 

$f = fopen($file, "r"); 

$row = 0; 
while (($data = fgetcsv($f, 0, ",")) !== FALSE) { 
    $multiple_categories = explode("|", $data); 
    //save main ones 
    $category->setName($multiple_categories[0]) 
     ->setIsActive(1)      
     ->setDisplayMode('PRODUCTS') 
     ->setIsAnchor(1) 
     ->setAttributeSetId($category->getDefaultAttributeSetId()); //or the id of your attribute set, this is important. 
    $category->save(); 
    unset($category); 
    //now deal with children 
    if(count($multiple_categories) > 1){ 
     i = 1; 
     foreach($multiple_categories as $subcategory){ 
      $category->setName($multiple_categories[i]) 
       ->setIsActive(1)      
       ->setDisplayMode('PRODUCTS') 
       ->setIsAnchor(1) 
       ->setAttributeSetId($category->getDefaultAttributeSetId()); 
      //manage parents now 
      $_category = Mage::getResourceModel('catalog/category_collection') 
       ->addFieldToFilter('name', $multiple_categories[i-1]) 
       ->getFirstItem(); //this needs more work 
      $parentId = $_category->getId(); 
      $parentCategory = Mage::getModel('catalog/category')->load($parentId); 
      $category->setPath($parentCategory->getPath()); 
      $category->save(); 
      unset($category); 
      i++; 
     } 
    } 
    $row++; 
} 
相關問題