Magento export categories -> import with magmi

Magento export categories -> import with magmi

September 21, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento export categories -> import with magmi

Exporting Categories for Magmi Import in Magento

Exporting category data is a common requirement when managing large product catalogs in Magento, especially if you need to update multiple categories simultaneously using the Magmi tool. In this post, we’ll guide you through the process of exporting categories in a format compatible with Magmi and discuss tools available for managing products within categories.

Exporting Categories via PHP Script

You’re on the right track by attempting to export category data via a custom PHP script. Here’s an improved version of your existing code that exports category paths in the desired format:

<?php
error_reporting(E_ALL | E_STRICT);
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
Mage::app();

$products = Mage::getModel("catalog/product")->getCollection();
$products->addAttributeToSelect('category_ids');
$products->addAttributeToSelect('sku');
$products->addAttributeToFilter('status', 1);//optional for only enabled products
$products->addAttributeToFilter('visibility', 4);//optional for products only visible in catalog and search

$fp = fopen('exports.csv', 'w');
$csvHeader = array("sku", "category_paths");
fputcsv( $fp, $csvHeader,",");

foreach ($products as $product){
    $sku = $product->getSku();
    $i = 0;
    $len = count($product->getCategoryIds());
    $str = "";

    foreach ($product->getCategoryIds() as $id) {
        $category = Mage::getModel('catalog/category')->load($id);
        if ($i > 0 && $i < $len) {
            $str .= "/";
        }
        $str .= $category->getName();
        $i++;
    }

    fputcsv($fp, array($sku, $str), ",");
}

fclose($fp);

Understanding the Modified Code

  1. We’ve renamed the second CSV column to category_paths for better readability.

  2. To ensure that categories are sorted by their ID and displayed in the correct path order (root category first), we load each category using its ID.

  3. Improved the logic for appending slashes between category names within the path string.

Managing Products Within Categories

If you find the above process cumbersome, consider exploring dedicated tools designed to simplify category management:

Magento Category Manager by Amasty (https://laravelcompany.com/magento-category-manager)

This extension offers a user-friendly interface for managing products across multiple categories simultaneously. Key features include:

  • Drag-and-drop functionality
  • Bulk product assignment
  • Filters and search options

Magmi Tool (http://sourceforge.net/projects/magmi/)

As mentioned, Magmi is an efficient tool for importing/exporting data in Magento. It supports various formats, including CSV files generated by our script above.

Conclusion

Exporting category data in a format compatible with Magmi can significantly streamline your catalog management workflows. By utilizing custom PHP scripts or dedicated extensions like Amasty’s Category Manager, you can efficiently update product categories without having to manually edit each record individually through the Magento admin interface.

Remember to backup your database before running any bulk updates and test thoroughly on a staging environment first.

Happy coding!

Catalog Import/Export Errors

Our network