To remove parent category path from child category url
Rewrite class Mage_Catalog_Model_Url
override method public function getCategoryRequestPath($category, $parentPath) like below
public function getCategoryRequestPath($category, $parentPath) { $storeId = $category->getStoreId(); $idPath = $this->generatePath('id', null, $category); $suffix = $this->getCategoryUrlSuffix($storeId); if (isset($this->_rewrites[$idPath])) { $this->_rewrite = $this->_rewrites[$idPath]; $existingRequestPath = $this->_rewrites[$idPath]->getRequestPath(); } if ($category->getUrlKey() == '') { $urlKey = $this->getCategoryModel()->formatUrlKey($category->getName()); } else { $urlKey = $this->getCategoryModel()->formatUrlKey($category->getUrlKey()); } $categoryUrlSuffix = $this->getCategoryUrlSuffix($category->getStoreId()); // Code commented to remove parent category path from child category path //if (null === $parentPath) { //$parentPath = $this->getResource()->getCategoryParentPath($category); //} //elseif ($parentPath == '/') { $parentPath = ''; //} $parentPath = Mage::helper('catalog/category')->getCategoryUrlPath($parentPath, true, $category->getStoreId()); $requestPath = $parentPath . $urlKey . $categoryUrlSuffix; if (isset($existingRequestPath) && $existingRequestPath == $requestPath . $suffix) { return $existingRequestPath; } if ($this->_deleteOldTargetPath($requestPath, $idPath, $storeId)) { return $requestPath; } return $this->getUnusedPath($category->getStoreId(), $requestPath, $this->generatePath('id', null, $category) ); }
Modified below code
if (null === $parentPath) { $parentPath = $this->getResource()->getCategoryParentPath($category); } elseif ($parentPath == '/') { $parentPath = ''; }
to
//if (null === $parentPath) { // $parentPath = $this->getResource()->getCategoryParentPath($category); //} elseif ($parentPath == '/') { $parentPath = ''; //}