Is there a way to export all categories into a csv?
You could write this one pretty easily. Create a PHP file called something like export.php
.
<?php
require("app/Mage.php"); // load the main Mage file
Mage::app(); // not run() because you just want to load Magento, not run it.
// load all of the active categories in the system and include all attributes
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter();
$export_file = "var/export/categories.csv"; // assumes that you're running from the web root. var/ is typically writable
$export = fopen($export_file, 'w') or die("Permissions error."); // open the file for writing. if you see the error then check the folder permissions.
$output = "";
$output = "id,name\r\n"; // column names. end with a newline.
fwrite($export, $output); // write the file header with the column names
foreach ($categories as $category) {
$output = ""; // re-initialize $output on each iteration
$output .= $category->getId().','; // no quote - integer
$output .= '"'.$category->getName().'",'; // quotes - string
// add any other fields you want here
$output .= "\r\n"; // add end of line
fwrite($export, $output); // write to the file handle "$export" with the string "$output".
}
fclose($export); // close the file handle.
You could write an import in a similar way, but use Mage::getModel('catalog/category')
with magic sets to fill in the fields to create new categories while parsing the file you've created.
Wasn't keen on @seanbreeden answer because it wont work properly if your exporting the category description and they have HTML or returns in any of the categories' fields like description etc.
Here's my solution (which you visit in the browser and it downloads it):
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=report.csv');
// Load the Magento core
require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(0);
// Load the category collection
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter();
// create a file pointer connected to the output stream
// can change this so it downloads it to a file on the server
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, array('id', 'name', 'description', 'title', 'meta_description'));
foreach ($categories as $category) {
$id = $category->getId();
$name = $category->getName();
$description = $category->getDescription();
$title = $category->getMetaTitle();
$metaD = $category->getMetaDescription();
fputcsv($output, array($id, $name, $description, $title, $metaD));
}