Để xóa đường dẫn danh mục cha mẹ khỏi url danh mục con
Phương thức ghi đè
lớp như bên dướiMage_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)
);
}
Sửa đổi mã dưới đây
if (null === $parentPath) {
$parentPath = $this->getResource()->getCategoryParentPath($category);
} elseif ($parentPath == '/') {
$parentPath = '';
}
đến
//if (null === $parentPath) {
// $parentPath = $this->getResource()->getCategoryParentPath($category);
//} elseif ($parentPath == '/') {
$parentPath = '';
//}
Use Parent Category Path for Category URLs
tùy chọn ce magento không có ở đó