Magento:在分层导航中显示兄弟类别
我想将兄弟类别添加到分层导航中(每当客户需要时) 已经有一层了) 换言之:假设我有一个名为“动物”的类别和分别名为“猫”、“狗”和“狮子”的子类别,如果客户单击“狮子”,我希望他们在“按类别购物”猫和狗中看到 有人知道怎么做吗Magento:在分层导航中显示兄弟类别,magento,Magento,我想将兄弟类别添加到分层导航中(每当客户需要时) 已经有一层了) 换言之:假设我有一个名为“动物”的类别和分别名为“猫”、“狗”和“狮子”的子类别,如果客户单击“狮子”,我希望他们在“按类别购物”猫和狗中看到 有人知道怎么做吗 提前谢谢。这应该不会太难。下面的代码未经测试,但无论您将其放在前端的何处,它都应该可以工作。它将为您提供对sibling类别集合的访问权限,但您需要找出将其放置在模板中的位置 $parentId = Mage::registry('current_category')-&
提前谢谢。这应该不会太难。下面的代码未经测试,但无论您将其放在前端的何处,它都应该可以工作。它将为您提供对sibling类别集合的访问权限,但您需要找出将其放置在模板中的位置
$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().", ";
}
这将检索同级类别的id、url和名称
$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);
去
app/code/core/Mage/Catalog/Model/Layer/Filter/Category.php
查找函数\u getItemsData()
见第163行:
删除此行并粘贴这些
if(count($categoty->getChildrenCategories())){
$categories = $categoty->getChildrenCategories();
}else{
$categories = $categoty->getParentCategory()->getChildrenCategories();
}
方法app/code/core/Mage/Catalog/Block/Navigation.php::getCurrentChildCategories()执行所需操作并保持产品计数正确。您可以将其功能复制到您自己的助手。通过Itoris检查扩展。它允许从父类别中筛选子类别。@RehanMonbin我尝试了您的解决方案,但在筛选所有其他子类别时,所选子类别的值均为
getProductCount()
0。如何获得与父类别处于活动状态时完全相同的类别过滤器块?如果动物类别被选择,然后分类为猫(3),狗(5),狮子(4),然后如果选择狗,然后猫和狮子显示积极的链接与积极的产品计数。请考虑覆盖,如果你选择这个解决方案。
if(count($categoty->getChildrenCategories())){
$categories = $categoty->getChildrenCategories();
}else{
$categories = $categoty->getParentCategory()->getChildrenCategories();
}