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.
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();
}
Finally fixed it with the following code, building on the exemplae of clockworkgeek. Thanks for that!
<?php
require 'app/Mage.php';
Mage::app();
$amount = 0;
$model = Mage::getModel('catalog/product');
$products = $model->getCollection();
foreach ($products as $product) {
$model->load($product->getId());
$product->setUrlKey($model->getName())->save();
set_time_limit();
$amount++;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With