Magento导出类别 - >与magmi进口 [英] Magento export categories -> import with magmi

查看:253
本文介绍了Magento导出类别 - >与magmi进口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要更改某些产品的类别,并且使用csv文件更容易实现。
有没有办法以magmi格式导出类别?

we need to change the categories of some products and it is easier for us to do this with a csv file. Is there a way to export the categories in magmi format?

sku,categories
"abc","cat1/cat2;;cat5/cat6/cat1"
"bgb","cat1/cat2"

还是可能有一个小工具来管理产品类别?

or is there maybe a small tool to manage the products in categories?

编辑:
这是显示类别的当前代码名。
但是我正在尝试显示类似的路径:

this is the current code which is displaying the category names. But I am trying to display the category path like this:

FirstCat/Tools/Screwdriver

但它显示如下:

FirstCat/Screwdriver/Tools

所以categoryid没有排序。

so the categoryid is not sorted.

<?php
error_reporting(E_ALL | E_STRICT);
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
Mage::app();
$products = Mage::getModel("catalog/product")->getCollection();
$products->addAttributeToSelect('category_ids');
$products->addAttributeToSelect('sku');
$products->addAttributeToFilter('status', 1);//optional for only enabled products
$products->addAttributeToFilter('visibility', 4);//optional for products only visible in catalog and search
$fp = fopen('exports.csv', 'w');
$csvHeader = array("sku", "category_ids");
fputcsv( $fp, $csvHeader,",");
foreach ($products as $product){
  $sku = $product->getSku();
  $i = 2;
  $len = count($product->getCategoryIds());
  $str = "";
  foreach ($product->getCategoryIds() as $id){
    $category = Mage::getModel('catalog/category')->load($id);
    $name = $category->getName();
    $str .= $name;
    if($i <= $len) {
      $str = $str .=  "/";
    }
    $i++;
  }

  fputcsv($fp, array($sku, $str), ",");

}
fclose($fp);


推荐答案

现在这里是我的解决方案。它在浏览器中显示csv。之后,您可以使用magmi重新导入

Now here is my solution. Its displaying the csv in the browser. After that you can reimport with magmi

<?php
error_reporting(E_ALL | E_STRICT);
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
Mage::app();
$products = Mage::getModel("catalog/product")->getCollection();
$products->addAttributeToSelect('category_ids');
$products->addAttributeToSelect('sku');
$products->addAttributeToFilter('status', 1);//optional for only enabled products
$products->addAttributeToFilter('visibility', 4);//optional for products only visible in catalog and search
foreach ($products as $product){
  $sku = $product->getSku();

  echo $sku.",";

  $i = 2;
  $anzahl = count($product->getCategoryIds());
  foreach ($product->getCategoryIds() as $id){
    $category = Mage::getModel('catalog/category')->load($id);
    $path = $category->getPath();

    $ids = explode("/", $path);
    $name = "";
    $i2 = 2;
    $anzahl2 = count($ids);
    foreach($ids as $id_2) {
      $category = Mage::getModel('catalog/category')->load($id_2);
      $name .= $category->getName();
      echo $category->getName();
      if($i2 <= $anzahl2) {
        $name .= "/";
        echo "/";
      }
      $i2++;
    }
    if($i <= $anzahl) {
      $name .= ";;";
      echo ";;";
    }
    $i++;

  }
  echo "<br />";
}

这篇关于Magento导出类别 - &gt;与magmi进口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆