将侧面分层导航中的Magento子类别更改为指向实际类别

时间:2012-12-27 21:32:35

标签: magento url layered-navigation

我想知道是否有任何方法可以将侧边栏导航的网址更改为指向实际类别。

例如,有一个父类别小部件,其中包含子类别计算机小部件,笔记本电脑小部件,电话小部件。如果您浏览主导航到手机小部件SEO友好URL将是www.example.com/widgets/phone-widgets,但如果您单击小部件类别,默认情况下您将有侧栏过滤导航类别计算机小部件,笔记本电脑小部件,手机小工具。如果您在此页面上单击“电话”窗口小部件,则该页面的URL将为www.example.com/widgets?cat=3。

有没有办法让这些侧面类别链接指向www.example.com/widgets/phone-widgets而不是www.example.com/widgets?cat=3?我真的想通过Magento代码而不是扩展或301重定向来实现。

提前谢谢!

3 个答案:

答案 0 :(得分:2)

我创建了一个解决此错误的模块。

https://github.com/jruzafa/Devopensource_LayerCatSeo

谢谢,

答案 1 :(得分:1)

使用此代码加载给定类别(按ID)

$category = Mage::getModel('catalog/category')->load($categoryId);

使用此功能获取友好网址

$category->getCategoryUrl();

答案 2 :(得分:1)

您可以覆盖Mage_Catalog_Model_Layer_Filter_Item的getUrl()方法。

以下是示例:

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();
  }
}