Magento – Full breadcrumb in product listing page

breadcrumbscategorymagento-1.9

As i browse through categories and subcategories
enter image description here

i can see the full breadcrumb. [Home > Electronics > Smartphone]

But as i enter the product listing page (After i selected apple)

enter image description here

i can't see that full breadcrumb. It only shows parent categories. [Home > Electronics]

Problem : how to get full categories and subcategories breadcrumb in my case [Home > Electronics > Smartphone > Apple]

Best Answer

Assuming your product only belongs to one category. You could override the getBreadcrumbPath function in Mage_Catalog_Helper_Data in this way:

if (!$this->_categoryPath) {

   $path = array();
   $category = $this->getCategory();

   if(!$category && $this->getProduct()) {

      $categoryIds = $this->getProduct()->getCategoryIds();
      if (is_array($categoryIds) and count($categoryIds)) 
          $category = Mage::getModel('catalog/category')->load(array_pop($categoryIds));
   }

   if ($category) {
   ...

Untested, but it should work