1

I would like to change the output of the breadcrumbs to be an attribute instead of the product name.

Example:

Home -> Category -> Product Name would become Home -> Category -> Magento_Attribute

I have tracked down 2 places where the breadcrumbs are generated:

/app/code/core/Mage/Catalog/Helper/Data.php

/**
 * Retrieve current Product object
 *
 * @return Mage_Catalog_Model_Product|null
 */
public function getProduct()
{
    return Mage::registry('current_product');
}

and /app/design/frontend/ultimo/default/template/page/html/breadcrumbs.phtml

I've been playing around with both files not having much luck.

How do I change the default behavior of the breadcrumbs product name to and attribute?

3
  • Had you already time to test my sugeestion?
    – sv3n
    Mar 20, 2018 at 22:23
  • yes - sorry for the delay
    – SR_Magento
    Mar 22, 2018 at 14:07
  • Sorry for repeated question :) But when I spent my time, getting some feedback is always nice ... even when my answer is wrong. So, thanks. :)
    – sv3n
    Mar 22, 2018 at 20:13

2 Answers 2

1

You can use core_block_abstract_to_html_before event to change breadcrumbs ...

<core_block_abstract_to_html_before>
    <observers>
        <some_alias>
            <class>module/observer</class>
            <method>setProductBreadcrumb</method>
        </some_alias>
    </observers>
</core_block_abstract_to_html_before>

In Observer.php set your own value for product crumb:

public function setProductBreadcrumb(Varien_Event_Observer $observer)
{
     $block = $observer->getBlock();
     if ($block instanceof Mage_Page_Block_Html_Breadcrumbs) {
         if ($product = Mage::registry('current_product')) {
             $block->addCrumb('product', array(
                 'label'    => $product->getSku(),
                 'title'    => $product->getSku(),
             ));
         }
     }
}

For modifing category crumbs you can use $block->addCrumb('category{id}', ....

0

in /app/design/frontend/ultimo/default/template/page/html/breadcrumbs.phtml Replace

<strong><?php echo $this->escapeHtml($_crumbInfo['label']) ?></strong>

with below code

<strong>
    <?php
    $product = Mage::registry('current_product');
    if($product){
        echo $product->getWeight();
    }else
    {
        echo $this->escapeHtml($_crumbInfo['label']);
    }   
    ?>
</strong>

and use your attributecode name instead of weight in getWeight

1
  • there is no <strong>, I tried in <span> no luck
    – SR_Magento
    Aug 27, 2017 at 10:00

Your Answer

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

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