Solution: Magento Catalog URL Rewrites Never Finishes (processing)

In Magento 1.4.2 and possibly other versions, you can often find that the Catalog URL Rewrite process will sit at Processing forever.

One of the problems that can cause this is if you have products in multiple categories and the solution is not pretty, but it works.

Copy the file /app/code/core/Mage/Catalog/Model/Url.php to /app/code/local/Mage/Catalog/Model/Url.php (You never edit core files right?!) and around line 770 there is the following code block :-

        // generate id_path
        if ('id' === $type) {
            if (!$product) {
                return 'category/' . $category->getId();
            }
            if ($category && $category->getLevel() > 1) {
                return 'product/' . $product->getId() . '/' . $category->getId();
            }
            return 'product/' . $product->getId();
        }

Changing this to the following seems to fix the problem :-

        // generate id_path
        if ('id' === $type) {
            if (!$product) {
                return 'category/' . $category->getId();
            }
            if ($category && (count(explode('/', $category->getPath())) - 1) > 1) {
                return 'product/' . $product->getId() . '/' . $category->getId();
            }
            return 'product/' . $product->getId();
        }

Tags: developmentproblemmagentosolution