-
Notifications
You must be signed in to change notification settings - Fork 1
/
exportCategories.php
55 lines (54 loc) · 1.86 KB
/
exportCategories.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Step 1 of 4: Write the following code in category.php and place it to root directory. Run this file at browser http://www.example.com/exportCategories.php. It will generate a CSV file Categories.csv (export all categories).
*/
<?php
ini_set("memory_limit","10000M");
require_once "app/Mage.php";
umask(0);
Mage::app();
$category = Mage::getModel ( 'catalog/category' );
$tree = $category->getTreeModel ();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
if ($ids) {
$string='';
$heading = '"store","categories","cat_id","is_active","meta_title","meta_keywords","meta_description","include_in_menu","is_anchor","description",';
foreach ($ids as $id){
if($id>0)
{
$cate_cre = Mage::getModel('catalog/category');
$cate_cre->load($id);
$treeurl='';
$cate_cre1=Mage::getModel('catalog/category')->load($id);
$treeurl=$cate_cre->getName();
if($cate_cre1->getParentId()>0)
{
for($i=0; ;$i++)
{
if($cate_cre1->getParentId()>0)
{
$abc=Mage::getModel('catalog/category')->load($cate_cre1->getParentId());
$pCat=$abc->getName();
if($abc->getId()>1){
$treeurl=$pCat.'/'.$treeurl;
}
$cate_cre1=$abc;
}
else{
break;
}
}
}
$store = "default";
$string .='"'.$store.'","'.$treeurl.'","'.$id.'","'.$cate_cre->getIsActive().'","'.$cate_cre->getMetaTitle().'","'.$cate_cre->getMetaKeywords().'","'.$cate_cre->getMetaDescription().'","'.$cate_cre->getIncludeInMenu().'","'.$cate_cre->getIsAnchor().'","'.$cate_cre->getDescription().'"';
$string.="\n";
}
}
$csv_output = $heading ."\n".$string;
$filename = "Categories";
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
}
?>