0

I have recently setup a new international store with english product titles, whereas my product titles are originally in danish. Now I need to regenerate all URLs for this store view, to use the english title instead of the old danish ones that are currently.

I order to do this, I guess I have to remove all existing URLs from this store and let magento create new ones. But what is the easiest way of doing this for around 2k products?

Thanks!

3

Here's a number of options:

  1. Update the URL keys the same way you updated the product titles.
  2. Export, transform values, import.
  3. Unset the URL keys programmatically and have them regenerated automatically.

While the former are rather self-explanatory, this is how the scripted approach looks like:

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->setStoreId($newStoreId);
$collection->addStoreFilter($newStoreId);
$collection->addAttributeToSelect('*');

foreach ($collection as $product) {
    $product->setStoreId($newStoreId);

    // disable adding entries to url rewrite rules (optional):
    $product->setSaveRewritesHistory(false);

    // if there are already url keys on store scope:
    $product->unsUrlKey();

    // otherwise, if the new store uses default values from parent scope:
    $urlKey = $product->formatUrlKey($product->getName());
    $product->setUrlKey($urlKey);
}

$collection->save();

By default, URL rewrites are added to the system. You can optionally turn that behaviour off.

Unsetting the URL key will only have effect if the product already has a URL key in the new store scope. If the product pulls its URL key from a website or default scope, the new URL key must be set explicitly.

  • Yeah, option 3 is what is was looking for. I will try using your code snippet. Thanks! – user2806026 Sep 15 '15 at 8:23
  • I was just about to do this, but then I realized.. Will this create URL forwards for the old URLs? – user2806026 Sep 29 '15 at 13:47
  • Answer updated to include information on catalog url rewrites. – mam08ixo Oct 30 '15 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.