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 个主要和子类别,因此手动创建它们根本行不通。

欢迎提出想法、问题或意见!:)

4

2 回答 2

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++;
}
于 2016-01-06T14:46:34.690 回答
0

MAGMI 'on-the-fly category importer' 肯定会为您做到这一点。我建议您非常非常仔细地阅读 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_active,is_anchorinclude_in_menu, 可以省略。

这不关我的事,但我对子类别标签中的两个空格深感担忧'Tools for alupex'(不要以小写的 Alupex 或 AluPEX 开头)

于 2016-01-06T21:54:47.603 回答