2012-01-09 42 views
2

我想添加同级类别到分层导航(每当客户是 已经有一层)。Magento:显示分层导航中的同级类别

换句话说:假设我有一个名为'Animals'的类别和分别名为'Cats''Dogs'和'Lions'的子类别,如果客户点击'狮子'我希望他们在“Shop按类别分类“猫和狗”。

有没有人有任何想法如何做到这一点?

在此先感谢。

+0

检查[多类别分层导航(http://www.itoris.com/magento-layered -navigation.html)由Itoris扩展。它允许从父类别过滤子类别。 – nico 2013-08-11 03:14:18

回答

7

这应该不会太难。下面的代码没有经过测试,但它应该在你把它放在前端的任何地方。它会做的是让你访问同级类别的集合,但是你需要找出你放置的模板的位置。

$parentId = Mage::registry('current_category')->getParentCategory()->getId(); 
$cats = Mage::getModel('catalog/category')->load($parentId)->getChildrenCategories(); 
foreach ($cats as $cat) { 
    // first, skip current category. 
    if ($cat->getId() == Mage::registry('current_category')->getId()) continue; 
    // then do something with $cat 
    echo $cat->getName().", "; 
} 
0

这将检索同级类别的ID,网址和名称

$currentCategory = $this->helper('catalog/data')->getCategory(); 
$parentCategoryId = $currentCategory->parent_id; 

$siblingCategoryIds = array(); 
$siblingCategories = array(); 

foreach(Mage::getModel('catalog/category')->load($parentCategoryId)->getChildrenCategories() as $siblingCategory) { 
    if ($siblingCategory->getIsActive()) { 
     $siblingCategories[] = array($siblingCategory->getId(), array('name' => $siblingCategory->getName(), 'url' => $siblingCategory->getUrl())); 
     $siblingCategoryIds[] = $siblingCategory->getId(); 
    } 
} 

$pos = array_search($currentCategory->getId(), $siblingCategoryIds); 

$nextPos = $pos+1; 
$prevPos = $pos-1; 

if (isset($siblingCategoryIds[$nextPos])) { 
    $nextCategory = $siblingCategories[$nextPos]; 
} 
else { 
    $nextCategory = null; 
} 

if (isset($siblingCategoryIds[$prevPos])) { 
    $prevCategory = $siblingCategories[$prevPos]; 
} 
else { 
    $prevCategory = null; 
} 

echo var_dump($prevCategory); 
echo var_dump($nextCategory); 
1

转到

应用程序/代码/核心/法师/目录/型号/层/过滤器/Category.php

查找功能_getItemsData()

看到线#163:

$categories = $categoty->getChildrenCategories(); 

删除此行并粘贴这些

if(count($categoty->getChildrenCategories())){ 
    $categories = $categoty->getChildrenCategories(); 
}else{ 
    $categories = $categoty->getParentCategory()->getChildrenCategories(); 
} 
+0

@RehanMonbin我试过你的解决方案,但在过滤所有其他子类别,除了选择'getProductCount()'零。我如何才能获得与父类别完全相同的类别过滤器块?说如果选择了动物类别,然后将类别分类为猫(3),狗(5),狮子(4),然后如果选择了狗,则猫和狮子显示积极的产品数量链接。 – Sandesh 2014-06-24 11:53:39

+2

如果您选择此解决方案,请考虑覆盖 – 2014-10-06 08:46:50