Magento – Force Display Full Breadcrumb Path

The best practice is to override this function and create a new module. For the time being we can use the easier method 🙂

Copy core file to local: app\code\local\Mage\Catalog\Block\Breadcrumbs.php
On protected function _prepareLayout() add below code just before $title = array();

$current_category   = Mage::registry('current_category');
$current_product    = Mage::registry('current_product');
if(!$current_category && $current_product){
    $categories = $current_product->getCategoryCollection()->addAttributeToSelect('name')->setPageSize(1);
    foreach($categories as $category) {
        Mage::unregister('current_category');
        Mage::register('current_category', $category);
    }
}

After this addition of code, you will always get full magento breadcrumb. Full code looks like below:

protected function _prepareLayout()
{
    if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
        $breadcrumbsBlock->addCrumb('home', array(
            'label'=>Mage::helper('catalog')->__('Home'),
            'title'=>Mage::helper('catalog')->__('Go to Home Page'),
            'link'=>Mage::getBaseUrl()
            ));

        // Fix for Breadcrumbs start here
        $current_category   = Mage::registry('current_category');
        $current_product    = Mage::registry('current_product');
        if(!$current_category && $current_product){
            $categories = $current_product->getCategoryCollection()->addAttributeToSelect('name')->setPageSize(1);
            foreach($categories as $category) {
                Mage::unregister('current_category');
                Mage::register('current_category', $category);
            }
        }
        // Fix for Breadcrumbs ends here

        $title = array();
        $path  = Mage::helper('catalog')->getBreadcrumbPath();

        foreach ($path as $name => $breadcrumb) {
            $breadcrumbsBlock->addCrumb($name, $breadcrumb);
            $title[] = $breadcrumb['label'];
        }

        if ($headBlock = $this->getLayout()->getBlock('head')) {
            $headBlock->setTitle(join($this->getTitleSeparator(), array_reverse($title)));
        }
    }
    return parent::_prepareLayout();
}

Advertisements
Magento – Force Display Full Breadcrumb Path

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s