The code below is tested on CE-1.7.0.2. It should work for EE1.12. It looks like it doesn't work for EE-1.13.
The url of a category is determined by the url_path
attribute of that category.
So you need to change the way that url_path
is generated when adding a new category.
For that you need to rewrite Mage_Catalog_Model_Url::getCategoryRequestPath
and change this line:
$requestPath = $parentPath . $urlKey . $categoryUrlSuffix;
into this one:
if (in_array($category->getLevel(), array(2, 3))){
$requestPath = $urlKey.$categoryUrlSuffix;
}
else {
$requestPath = $parentPath . $urlKey . $categoryUrlSuffix;
}
This means that for level 2 and 3 categories (that are actually level 1 and 2 in the menu) you don't add in front of the url key the parent path.
The url path for the level 2 and 3 categories will consist only of the url_key you enter manually in the admin and the suffix (.html
).
But there is a catch. This will only work for the new categories you add. The old ones will still have the classic path parent/child/grandchild.html
.
TO change this behavior run the following code before adding new categories.
$collection = Mage::getResourceModel('catalog/category_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('level', array('gt'=>2));
foreach ($collection as $category){
$path = $category->getUrlPath();
$parts = explode('/', $path);
if (count($parts) > 1){
unset($parts[0]);
$path = implode('/', $parts);
}
$category->setUrlPath($path);
Mage::getResourceSingleton('catalog/url')->saveCategoryAttribute($category, 'url_path');
}
The code above will change the url path for the existing categories in the desired format.
Rebuild your indexes and everything will look as you want.
You will even get 301 redirects for the existing categories from parent/child/grandchild.html
to child/grandchild.html
Note: backup your database just in case I'm wrong.