问题
I was wondering if there is any way to change URLs of sidebar navigation to point to actual categories.
For example there is a parent category widgets with subcategories Computer widgets, Laptop widgets, Phone widgets. If you navigate through main navigation to phone widget SEO friendly URL will be www.example.com/widgets/phone-widgets, but if you click on widget category, by default you going to have sidebar filtering navigation with categories Computer widgets, Laptop widgets, Phone widgets. If, on this page you will click on Phone widgets, the URL of the page will be www.example.com/widgets?cat=3.
Is there any way to make those side category links to point to www.example.com/widgets/phone-widgets instead of www.example.com/widgets?cat=3? I would really like to do it through Magento code rather than extension or 301 redirect.
Thank you in advance!
回答1:
I created a module that solves this error.
https://github.com/jruzafa/Devopensource_LayerCatSeo
Thanks,
回答2:
Use this code to load the given category (by ID)
$category = Mage::getModel('catalog/category')->load($categoryId);
Use this to get friendly URL
$category->getCategoryUrl();
回答3:
You can override getUrl() method of Mage_Catalog_Model_Layer_Filter_Item.
Here is example:
public function getUrl()
{
$value = $this->getValue();
$query = array(
$this->getFilter()->getRequestVar() => $value,
Mage::getBlockSingleton('page/html_pager')->getPageVarName() => null // exclude current page from urls
);
$url = Mage::getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true, '_query'=>$query));
if ($this->getFilter()->getRequestVar() != 'cat') {
return $url;
}
// Change ?cat=4 for real category url if no additional filters are present
// www.x.com/y?cat=4
// =>
// www.x.com/y/z
$pos = strpos($url, '&');
if ($pos !== false) {
return $url;
} else {
// no additional filters
return Mage::getModel('catalog/category')->load($value)->getUrl();
}
}
来源:https://stackoverflow.com/questions/14061575/change-magento-subcategories-in-side-layered-navigation-to-point-to-actual-categ