如何从magento导出csv文件中的类别,该类别可以直接导入到Neto?
答案 0 :(得分:0)
创建一个PHP文件示例categories.php
并将其放置在magento
根目录下,然后在该文件中放置以下代码:
<?php
error_reporting(E_ALL);
ini_set("memory_limit", "100000M");
include("app/Mage.php");
umask(0);
Mage::app();
$data=array();
// Neto like Csv header, modify it according to you
$csv_header=Array
(
0 => "Content Type",
1 => "Content Path",
2 => "Name",
3 => "Description 1",
4 => "Description 2",
5 => "SEO Meta Description",
6 => "Sort Order",
7 => "SEO Page Title",
8 => "SEO Meta Keywords",
);
$data[0]= $csv_header;
/* magento category fetching start */
function getChildCategories($category, $isFirst = false) {
$children = $isFirst ? $category : $category->getChildren();
foreach ($children as $child) {
$_categories[] = [ "name" => $child->getName(), "id" => $child->getId(), "children" => getChildCategories($child) ];
}
return $_categories;
};
$_categories = Mage::helper('catalog/category')->getStoreCategories();
$categories = getChildCategories($_categories, true);
// put desired field in below array
$csvData=array();
foreach($categories as $key=>$val){
$csvData[0]="Product Category";
$csvData[1]="";
$csvData[2]=$val['name'];
$csvData[3]="";
$csvData[4]="";
$csvData[5]="";
$csvData[6]=0;
$csvData[7]="";
$csvData[8]="";
$data[]=$csvData;
}
$csvData=array();
foreach($categories as $key=>$val){
$csvData[0]="Product Category";
$csvData[1]=$val['name'];
if(isset($val["children"])){
$childs=$val["children"];
foreach($childs as $child){
$csvData[2]=$child['name'];
$csvData[3]="";
$csvData[4]="";
$csvData[5]="";
$csvData[6]=0;
$csvData[7]="";
$csvData[8]="";
$data[]=$csvData;
}
}
}
// generate csv
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="productCategories.csv"');
$fp = fopen('php://output', 'wb');
foreach ($data as $line) {
fputcsv($fp, $line, ',');
}
fclose($fp);
然后在像yourDomain/categories.php
这样的浏览器中调用此文件,您将获得一个csv,可以直接将其导入到Neto
存储中。