Magento Export Category List as CSV Format

Using the below code, you can export magneto category list as CSV format. Place the code in your root directory, and the exported file will be saved on  var/export directory.  So the CSV format includes

"Root Category Id", "Category Id", "Category Name", "Category URL", "Category Image", "Category Page Title", "Category Meta Keywords", "Category Mate Description","Category Is Active"
require_once 'app/Mage.php';
Mage::app();
$mageCategory = Mage::getModel ( 'catalog/category');
$categoryTree = $mageCategory->getTreeModel();
$categoryTree->load();
$categoryListIds = $categoryTree->getCollection()->getAllIds();
if ($categoryListIds) {
    $outputFileDir = "var/export/categories-detail.csv";
    $writeFile = fopen($outputFileDir, 'w');
    foreach ($categoryListIds as $categoryListId) {
        $categoryModel = $mageCategory->load($categoryListId);
        $parentCategoryId = $categoryModel->getParentId();
        $categoryId = $categoryModel->getId();
        $categoryName = $categoryModel->getName();
        $categoryUrl = $categoryModel->getUrl();
        $categoryImage = $categoryModel->getImage();
        $categoryPageTitle = $categoryModel->getMetaTitle();
        $categoryPageKeywords = $categoryModel->getMetaKeywords();
        $categoryPageDescription = $categoryModel->getMetaDescription();
        $categoryActive = $categoryModel->getIsActive();
        $collection = $mageCategory->getProductCollection();
        $data = array($parentCategoryId, $categoryId, $categoryName, $categoryUrl, $categoryImage, $categoryPageTitle, $categoryPageKeywords, $categoryPageDescription, $categoryActive);
        fputcsv($writeFile, $data);
        $i++;
    }
}
fclose($write);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s