Clearing URL keys in Magento
magento
Solution
Here's a quickie that isn't even tested. It might take a long time if there are many products but it will also update the rewrite records at the same time. Copy this into a .php file in your site's root and execute it.
<?php
require 'app/Mage.php';
Mage::app();
$products = Mage::getModel('catalog/product')->getCollection();
foreach ($products as $product) {
$product->setUrlKey($product->getSku())
->save();
}
Problem
I've setup a magento installation for a shopowner who has added his own products. Unfortunataly he didn't understand the URl key field. As he duplicated the product, each product now has the same URL with a incrementing number /product-1234.html, next one /product-1235.html. Since he has almost 2k products, it will be a hassle to manually adjust all the url key's. Is there some way to clear this in magento (or straight on the DB) without ruining the shop. It seems that if I delete one URL-key magento auto-generates one, which is fine for me. Edit: Okay, so I've found how I can reset the URL key's by clearing certain fields in a database table (catalog_product_entity_varchar), but now I need Magento to create new ones using the product name. Any ideas? Thanks.