Export Magento categories to CSV

7designstudio Magento Blog Image

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. CSV format includes

"Root Category Id", "Category Id", "Category Name", "Category URL", "Category Image", "Category Page Title", "Category Meta Keywords", "Category Meta 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);

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2018 7Design.Studio | Web Design, Web Application Development & UX Design | Chennai | India

Up ↑