Magmi overwriting position of products in category

Magmi overwriting position of products in category

September 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magmi overwriting position of products in category

Solving Magmi Product Position Overwrite Issues

If you’re finding that your Magento product positions within categories are consistently being overwritten to zero when using Magmi for imports, don’t worry - this is a common issue with a simple solution. Let’s dive into why it happens and how to fix it.

Understanding the Problem: Magmi’s Default Behavior

Magmi, by default, always sets the position of imported products back to 0 regardless of their previous position in the category. This behavior can be quite frustrating, especially when you’ve carefully curated your product sorting within categories.

The root cause lies in Magmi’s bulk processing nature combined with Magento’s database constraints. When Magmi updates a product’s data in bulk, it has to reset certain fields like ‘position’ for consistency sake before re-saving them.

Resolving the Issue: Maintain Previous Positions

To maintain your product positions across imports without having to manually sort them each time, you can utilize one of these two approaches:

1. Exclude category_position from Magmi’s Update Process

You can configure Magmi to exclude the ‘category_position’ field from its update process entirely. This ensures that it won’t touch this field during imports.

To do this:

  • Open your Magmi configuration profile.
  • Go to the “Update Fields” section.
  • Remove or comment out category_position from the list of fields.

This way, only new products will have their positions set to 0 (as they are not part of any category yet), but existing products’ positions remain untouched during updates.

2. Implement a Custom Positioning Script

For more advanced use cases or when you need complete control over product positioning, consider creating a custom script that runs after the Magmi import.

This script could look like this (written in PHP):

<?php
require_once 'app/Mage.php';
Mage::init();

// Fetch all categories and their products
$categories = Mage::getModel('catalog/category')->getCollection();
foreach ($categories as $category) {
    // Get children category IDs
    $children = $category->getChildrenCategories();

    foreach ($children as $childId => $subCategory) {
        $_products = $subCategory->getProductCollection()->addAttributeToSelect('position');

        // Sort products based on their position attribute
        usort($products, function ($a, $b) {
            return $a['position'] - $b['position'];
        });

        // Re-save the sorted product collection with the same positions
        foreach ($products as $product) {
            $product->save();
        }
    }
}

This script retrieves all categories and their subcategories, fetches the associated products, sorts them based on their ‘position’ attribute, and then re-saves each product. This effectively preserves your sorting without Magmi overwriting it.

Best Practices for Magento Product Positioning

To make your life easier with product positioning in Magento:

  • Always use integer values for the position.
  • Avoid using floating point numbers or non-integer strings as they can cause issues with Magmi and other tools.
  • For complex sorting requirements, consider using a custom attribute instead of the built-in ‘position’ field.

Conclusion: Achieving Product Sorting Stability

Remember that maintaining product positions across imports is all about controlling what fields Magmi updates and handling any necessary post-import cleanup. By following either of the above approaches or even combining them for added robustness, you can achieve stable product sorting within categories without having to manually re-sort your products after every import.

Don’t forget to check out our guide on Optimizing Magento Performance for more tips on streamlining your e-commerce workflows.

Happy coding!

Catalog Database Themes Configuration

Our network