I am using Magento CE I can't seem to get the category URL key to save properly. If I add the category through the admin panel, everything works fine. But I am trying to add the categories programatically.

The problem is that the url_key that I am setting is being ignored, and a differnet url_key is being generated based on the name of the category.

$storeId = 3; // my store ID
$parentId = 18; // the root category ID
$category = Mage::getModel('catalog/category');
$category->setName('Contact Us');
$parentCategory = Mage::getModel('catalog/category')->load($parentId);
$savedCategoryId = $category->getId();
$category = Mage::getModel('catalog/category')->load($savedCategoryId);
// I get 'contact-us' instead of 'customer-service-contact-us'     

I expected to get 'customer-service-contact-us' for the url key, but instead I'm getting the auto-generated url key 'contact-us'.

Any insight would be greatly appreciated. I've tried disabling all 3rd party modules, but the problem still happens.

1 Answer 1


The problem was the store ID.


$storeId = 3; // my store ID


$storeId = 0; // my store ID

Even though 3 is the correct store ID, the category model won't save the custom url_key unless you set the store ID to 0 (all stores).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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