Return to Snippet

Revision: 39059
at January 12, 2011 23:05 by TheJasonParker


Initial Code
<?php
 
	define('MAGENTO', realpath(dirname(__FILE__)));
	require_once MAGENTO . '/app/Mage.php';
	Mage::app();
 
	$category = Mage::getModel ( 'catalog/category' );
	$tree = $category->getTreeModel ();
	$tree->load ();
 
	$ids = $tree->getCollection ()->getAllIds ();
 
	if ($ids) {
		$file = "var/import/catwithid.csv";
		file_put_contents($file,"catId, catName\n");
		foreach ( $ids as $id ) {
		  $string = $id . ', ' .$category->load($id)->getName() . "\n";
			file_put_contents($file,$string,FILE_APPEND);
		}
	}
?>

Initial URL
http://www.sonassi.com/knowledge-base/quick-script-to-export-categories-with-ids/

Initial Description
Simply save the above code in a PHP file in the base Magento directory of your store, and visit the URL in your web browser, simples!

Initial Title
Export categories with ID's

Initial Tags
magento

Initial Language
PHP