Maybe someone will need it, so here we go with code:
echo "<pre>"; $category = Mage::getModel('catalog/category'); $tree = $category->getTreeModel(); $tree->load(); $ids = $tree->getCollection()->getAllIds(); $categories = array(); if ($ids) { foreach ($ids as $id) { $category->load($id); $categories[$id]['name'] = $category->getName(); $categories[$id]['path'] = $category->getPath(); } foreach ($ids as $id) { $path = explode('/', $categories[$id]['path']); $string = ''; foreach ($path as $pathId) { $string.= $categories[$pathId]['name'] . ' > '; $cnt++; } $string.= ';' . $id . "\n"; echo $string; } }
the snippet above will give you such output:
root category 1 ; 1
root category 1 > subcategory 1 ; 2
root category 1 > subcategory 1 > subsubcategory 1 ; 3
root category 1 > subcategory 1 > subsubcategory 2 ; 4
root category 1 > subcategory 2 ; 5
root category 1 > subcategory 2 > subsubcategory 1 ; 6
Thanks, so useful.
How to export current product category like this category tree?
Hello;
i need current category tree menu can i know how can i do that?
Thanks in advance
\n didn’t worked for me, so I used PHP_EOL. Also I added some code from another php-Script to save the category-tree in a .csv file (path=var/export/catwithid.csv):
Thanks for neat snippet. For folks who wants to fetch all categories (not just current store categories), make sure your script is executed in admin store. Something like the code below will help. When script is ran as admin-store categories are read from ‘catalog_category_entity’ table. Without admin, categories are fetched from catalog_category_flat_store_x table.
Very cool, I really need this but it gives me an “Access denied.” on screen, Help!
How can i add sku for this
How can i add sku for above code
how to export sku, category path(name not id)