子カテゴリのURLから親カテゴリのパスを削除するには 、以下のように
クラスのMage_Catalog_Model_Url
オーバーライドメソッドを書き換えpublic function getCategoryRequestPath($category, $parentPath)
ます
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)
);
}
コードの下で変更
if (null === $parentPath) {
$parentPath = $this->getResource()->getCategoryParentPath($category);
} elseif ($parentPath == '/') {
$parentPath = '';
}
に
//if (null === $parentPath) {
// $parentPath = $this->getResource()->getCategoryParentPath($category);
//} elseif ($parentPath == '/') {
$parentPath = '';
//}
Use Parent Category Path for Category URLs
オプションはありません