Skip to content

Instantly share code, notes, and snippets.

@scgoeswild
Last active November 17, 2020 15:45
Show Gist options
  • Save scgoeswild/ee535313c012b0bdeec962e9d12b387a to your computer and use it in GitHub Desktop.
Save scgoeswild/ee535313c012b0bdeec962e9d12b387a to your computer and use it in GitHub Desktop.
Magento 1.9 export categories with TreeModel
<?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",';
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() . '"';
$string.= "\n";
}
}
$csv_output = $heading . "\n" . $string;
$filename = "Categories-de";
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;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment