How To Display Full Breadcrumb Path in Magento?

In magento website facing Breadcrumbs path to display full breadcrumbs path if category is not include in path.

To fix this here can use this small and easy way to fix and display your full breadcrum path.

To fix this problem here simple step to add some code that is:

First open your breadcrumb.php file from core folder to local folder like

Core:
app\code\core\Mage\Catalog\Block\Breadcrumbs.php to Local

Local:
app\code\local\Mage\Catalog\Block\Breadcrumbs.php
Now open this copied Breadcrumb file in your favorite editor
find protected function _prepareLayout() and add this code just before this array

“$title = array();”

Code to be add:

==========================================================================
//$current_category = Mage::registry(‘current_category’);
$current_product = Mage::registry(‘current_product’);
if($current_product){
$categories = $current_product->getCategoryCollection()->addAttributeToSelect(‘name’);
foreach($categories as $category) {
Mage::unregister(‘current_category’);
Mage::register(‘current_category’, $category);
}
}

============================================================================

Once done this add  above bit of code your full breadcrumb .php file looks like :

———————————————————————————————————————————-
/**
* Preparing layout
*
* @return Mage_Catalog_Block_Breadcrumbs
*/
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()
));
// sometimes magento can’t get category associated with a product

// so the full breadcrumb is not shown to fix this issue this is the bit of code

//$current_category = Mage::registry(‘current_category’);
$current_product = Mage::registry(‘current_product’);
if($current_product){
$categories = $current_product->getCategoryCollection()->addAttributeToSelect(‘name’);
foreach($categories as $category) {
Mage::unregister(‘current_category’);
Mage::register(‘current_category’, $category);
}
}
foreach($categories as $category) {
Mage::unregister(‘current_category’);
Mage::register(‘current_category’, $category);
}
}
$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();
}

——————————————————————————————————————————–

save the file and upload in to your root path by using cpanel or ftp.

Hope it will help.

You must be logged in to post a comment Login