5

In my site I need to show all (Display Full Breadcrumb Path) category and sub category in breadcrumbs.

My product in many category like this :

Shirts >> full sleeves >> product A
T-Shirts >> Polo >> product A
Sweaters >> Woolen >> product A
Men >> Dresses >> product A

Like above I want to display all in breadcrumb [all categories which the product belongs to] in next next lines.

How to achieve this ?

2 Answers 2

2

I did the extension in below GitHub Url with below feature :

https://github.com/vijays91/Magento-Advanced-Breadcrumbs

  • Display the full path in product breadcrumbs (show all category paths).
  • To display the single and multiple category breadcrumbs in product view page.
  • Helps this module, search engines to parse your breadcrumbs (Home / Search result for: 'XXX' / XXX).
  • Breadcrumbs are added to customer account pages.
  • Added breadcrumbs to contact us page.
2
  • 1
    single link answers are not the best answers. Try to add a few words about how your extension works.
    – Marius
    Jun 23, 2016 at 12:20
  • Sure, I updated the answer @Marius
    – VijayS91
    Jun 23, 2016 at 13:17
1

First of all you have to modify page/html/breadcrumb.phtml checking if you are in a product's page and then change your breadcrumb behaviour.

Something like this:

<?php if ($_product = Mage::registry('current_product')): ?>
    <?php
    $cats = $_product->getCategoryIds();
    ?>
    <?php foreach ($cats as $catId): ?>
        <div class="breadcrumbs">
            <ul>

                <?php $_cat = Mage::getModel('catalog/category')->load($catId); ?>
                <?php
                $parentPath = explode('/', $_cat->getPath());
                $parentPath = array_splice($parentPath, 2);
                ?>
                <?php foreach ($parentPath as $parentId): ?>
                    <?php $_prentCat = Mage::getModel('catalog/category')->load($parentId); ?>
                    <li><?php echo $_prentCat->getName() ?></li>
                <?php endforeach ?>
                <li><?php echo $_product->getName() ?></li>

            </ul>
        </div>
    <?php endforeach; ?>

<?php else: ?>
    ... // Standard breadcrumb code
<?php endif; ?>

For best performance use this:

<?php if ($_product = Mage::registry('current_product')): ?>
    <?php $cats = $_product->getCategoryIds(); ?>
    <?php foreach ($cats as $catId): ?>
            <div class="breadcrumbs">
                <ul>

                    <?php $parentPath = Mage::getResourceModel('catalog/category')->getAttributeRawValue($catId, 'path'); ?>
                    <?php
                    $parentPath = explode('/', $parentPath);
                    $parentPath = array_splice($parentPath, 2);
                    ?>
                    <?php foreach ($parentPath as $parentId): ?>
                        <li><?php echo $this->escapeHtml(Mage::getResourceModel('catalog/category')->getAttributeRawValue($parentId, 'name')) ?></li>
                    <?php endforeach ?>
                    <li><?php echo $_product->getName() ?></li>

                </ul>
            </div>
        <?php endforeach; ?>
<?php else: ?>
... // Standard breadcrumb code
<?php endif; ?>
8
  • 3
    this does not give you the full category tree path. It only gives you the categories directly linked to the products. In the example the OP offered you will only get full sleeves, Polo, Woolen, Dresses. not to mention that calling load in a loop in a template is very bad for performance and for code aesthetics
    – Marius
    Feb 17, 2016 at 16:15
  • Yes, you are right, you can use $_cat->getPath() to get the category parents. Feb 17, 2016 at 16:18
  • I modified my original answer to include the parent categories, check it now. Feb 17, 2016 at 16:25
  • Now you have a load in 2 loops. It is even worse
    – Marius
    Feb 17, 2016 at 17:59
  • @Marius, they are different categories. To optimize it we should get all the ids and retrieve a collection. Do you have better options? Feb 17, 2016 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.