对于magento的面包屑导航,对于客户体验是挺不错的,但是带来的是seo推广的不利,譬如:在两个分类中都有一个产品,而产品的url是不包含分类的,这样就会造成从不同分类查看这个产品的url是一样的,但是面包屑导航却不一样,这样很不利于seo,需要吧导航定死!!!毕竟推广需要这样的。
修改办法为:
将Mage_Catalog_Helper_Data 里面的方法getBreadcrumbPath,替换成下面的,写的比较草!!
public function getBreadcrumbPath()
{
if ($this->getProduct() && !$this->getCategory()) {
$_categoryIds = $this->getProduct()->getCategoryIds();
$max = 0;
for($i=0;$i<count($_categoryIds);$i++){
$curr = $_categoryIds[$i];
if($curr>$max){
$max = $curr;
}
}
// echo $max."###";exit;
if($max!=0){
$_categoryId = $_categoryIds[$max];
$_category = Mage::getModel('catalog/category')->load($_categoryId);
Mage::register('current_category', $_category);
}
}
$_categoryIds = $this->getProduct()->getCategoryIds();
$_categoryId0 = $_categoryIds[0];
$_categoryId1 = $_categoryIds[1];
$_categoryId2 = $_categoryIds[2];
$_categoryId3 = $_categoryIds[3];
if($_categoryId1>$_categoryId0){
$_categoryId = $_categoryId1;
}else{
$_categoryId = $_categoryId0;
}
if($_categoryId<$_categoryId2){
$_categoryId = $_categoryId2;
}
if($_categoryId<$_categoryId3){
$_categoryId = $_categoryId3;
}
$_category = Mage::getModel('catalog/category')->load($_categoryId);
if (!$this->_categoryPath) {
$path = array();
if ($category = $_category) {
$pathInStore = $category->getPathInStore();
$pathIds = array_reverse(explode(',', $pathInStore));
$categories = $category->getParentCategories();
// add category path breadcrumb
foreach ($pathIds as $categoryId) {
if (isset($categories[$categoryId]) && $categories[$categoryId]->getName()) {
$path['category'.$categoryId] = array(
'label' => $categories[$categoryId]->getName(),
'link' => $this->_isCategoryLink($categoryId) ? $categories[$categoryId]->getUrl() : ''
);
}
}
}
if ($this->getProduct()) {
$path['product'] = array('label'=>$this->getProduct()->getName());
}
$this->_categoryPath = $path;
}
return $this->_categoryPath;
}
这样,通过不同的分类查看这个产品的时候的面包屑导航都是一样的了,通过bestseller,new product也是带有面包屑导航的了!!!!!!!!!!!!!!!!!!!