Skip to content

Instantly share code, notes, and snippets.

@peterjaap
Created October 15, 2013 16:03
Show Gist options
  • Save peterjaap/6993942 to your computer and use it in GitHub Desktop.
Save peterjaap/6993942 to your computer and use it in GitHub Desktop.
Dump categories to tabbed CSV file
<?php
chdir(dirname(__FILE__));
require_once '../app/Mage.php';
@$app = Mage::app($argv[1]);
$catalogId = $app->getStore()->getRootCategoryId();
$category = Mage::getModel ('catalog/category');
catalogTraversal($category,$catalogId);
function catalogTraversal( $category, $catalogId=null){
$curCatalog = $category->load($catalogId);
$childCats = $curCatalog->getChildrenCategories();
if (count($childCats) > 0){
foreach ($childCats as $childCat){
for ($j=0; $j<$childCat->getLevel(); $j++){
echo ',';
}
echo '"' . addslashes($childCat->getName()). '"->"'. $childCat->getId().'"';
echo "\n";
catalogTraversal($category, $childCat->getId());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment