Magento displays all categories on the product review page with parent categories

Following this question: Show ALL categories the Magento product belongs to

Is there a way to show the full path to the category (with links at each stage), and not just display the final category to which the product belongs?

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 } ?>

Which correctly binds the category name that is displayed on the page. I would like to show the full Cat> Sub Cat> Sub Sub Cat trail and link each item in this track.

0
source share
1 answer

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
    }
}

, . (, , ).

+3

Source: https://habr.com/ru/post/1776373/


All Articles