我想将兄弟类别添加到分层导航(无论何时是客户 已经有一层了。
换句话说:假设我有一个名为'动物'的类别和分别名为'猫''狗'和'狮子'的子类别,如果客户点击'狮子',我希望他们在“Shop by类别“猫与狗。
有没有人知道如何做到这一点?
提前致谢。
答案 0 :(得分: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().", ";
}
答案 1 :(得分:1)
转到
应用程序/代码/核心/法师/目录/型号/层/过滤/ Category.php
找到函数_getItemsData()
见第163行:
$categories = $categoty->getChildrenCategories();
删除此行并粘贴这些
if(count($categoty->getChildrenCategories())){
$categories = $categoty->getChildrenCategories();
}else{
$categories = $categoty->getParentCategory()->getChildrenCategories();
}
答案 2 :(得分:0)
这将检索兄弟类别的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);
答案 3 :(得分:0)
方法app / code / core / Mage / Catalog / Block / Navigation.php :: getCurrentChildCategories()执行所需的操作并保持产品计数正确。您可以将其功能复制到自己的助手中。