How to Export Magento Categories

export_categories

Magneto Data flow method will not export the categories. It used to export only the products. In this case you can run the below script inside your magento directory.

After run this script you can get the exported csv file insider the var/export directory with the file name cat_export.csv. in some cases if you don’t have permission for your var directory it will not allow to create the folder export. So you can manually create the export folder inside var directory.


<?php

define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$category = Mage::getModel ( 'catalog/category' );
$tree = $category->getTreeModel ();
$tree->load ();

$ids = $tree->getCollection ()->getAllIds ();

if ($ids) {
$file = "var/export/cat-export.csv";
file_put_contents($file,"Category ID, Category Name");
foreach ( $ids as $id ) {
$string = $id . ', ' .$category->load($id)->getName() . "\n";
file_put_contents($file,$string,FILE_APPEND);
}
}

Leave a Comment

Your email address will not be published. Required fields are marked *


4 × 2 =