Skip to content

Instantly share code, notes, and snippets.

@olragon
Created December 7, 2017 12:01
Show Gist options
  • Select an option

  • Save olragon/5aa8d13b4d5f2be9e58c51c7fb679b7b to your computer and use it in GitHub Desktop.

Select an option

Save olragon/5aa8d13b4d5f2be9e58c51c7fb679b7b to your computer and use it in GitHub Desktop.
Export Magento 1.x categories to csv
<?php
require_once 'app/Mage.php';
Mage::app();
$allCategories = Mage::getModel ( 'catalog/category' );
$categoryTree = $allCategories->getTreeModel();
$categoryTree->load();
$categoryIds = $categoryTree->getCollection()->getAllIds ();
if ($categoryIds) {
$outputFile = "var/export/categories.csv";
$write = fopen($outputFile, 'w');
foreach ( $categoryIds as $categoryId ) {
$category = $allCategories->load($categoryId);
$url_key = Mage::helper('catalog/category')->getCategoryUrlPath($allCategories->getUrlPath(), true);
$path = $category->getPath();
$data = array(
$categoryId,
$allCategories->load($categoryId)->getName(),
$path,
$url_key,
);
fputcsv($write, $data);
}
}
fclose($write);
?>
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment