Magento在产品查看页面上显示所有类别以及父类别 [英] Magento display all categories on product view page with parent categories

查看:109
本文介绍了Magento在产品查看页面上显示所有类别以及父类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接着是这个问题:显示所有类别产品属于Magento的

是否有办法显示完整的类别路径(每个阶段都有链接),而不是仅显示产品所属的最终类别?

Is there a way to display the full category path (with links at each stage) rather than only displaying the final category that a product belongs to?

到目前为止,我已经有了此代码...

I have this code so far...

<?php
            $currentCatIds = $_product->getCategoryIds();
            $categoryCollection = Mage::getResourceModel('catalog/category_collection')
                 ->addAttributeToSelect('name')
                 ->addAttributeToSelect('url')
                 ->addAttributeToFilter('entity_id', $currentCatIds)
                 ->addIsActiveFilter();
            foreach($categoryCollection as $cat){
            ?>
                <a href="<?php echo $cat->getUrl(); ?>">
                    <?php echo $cat->getName() ?>
                </a>
            <?php } ?>

正确链接页面上显示的类别名称. 我想显示完整的Cat> Sub Cat> Sub Sub Cat路径,并正确链接该路径中的每个元素.

Which correctly links the category name that is displayed on the page. What I would like is to display the full Cat > Sub Cat > Sub Sub Cat trail, and have each element in that trail correctly linked.

推荐答案

如何处理:

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).

这篇关于Magento在产品查看页面上显示所有类别以及父类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆