Magento display all categories on product view page with parent categories

大兔子大兔子 提交于 2019-12-01 14:47:32

How about this:

foreach($categoryCollection as $cat){
    $parents = $cat->getCollection()
        ->addIdFilter($cat->getParentIds())
        ->addAttributeToSelect('name')
        ->addUrlRewriteToResult()
        ->setOrder('level');
    foreach ($parents as $parentCat) {
        // Build your parent links
    }
}

By the way, this kind of code doesn't belong in the template. It should go into a method of the block being rendered (or at least into a helper).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!