cancel
Showing results for 
Search instead for 
Did you mean: 

Full Path Breadcrumbs

Full Path Breadcrumbs

As most face with Magento, the breadcrumbs does not display the full path unless you navigate through the categories.  Just hitting the URL causes the breadcrumbs to be home/product.

 

I came across this github https://github.com/dbashyal/Magento_Breadcrumbs.  It works fine on our dev site but i'm curious if it will slow down our site at all or if there is anything that we need to change?  Here is the observer.php file that does all the work:

 

<?php
/**
* @category   Technooze/Modules/Magento_Breadcrumbs
* @package    Technooze_Breadcrumbs
* @author     Damodar Bashyal (http://dltr.org/)
* @author     Chris Pook (http://j.mp/1FQTjVz)
* @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*/
class Technooze_Breadcrumbs_Model_Observer
{
	/**
	* Adds category to breadcrumb for product views 
	* originating from outside a category, for instance
	* homepage or navigation links.
	*
	* @return Technooze_Breadcrumbs_Model_Observer
	*/
	public function addCategoryBreadcrumb(Varien_Event_Observer $observer)
	{
		if (!Mage::registry('current_category')) {
            /* @var $product Mage_Catalog_Model_Product */
			$product = $observer->getProduct();
			$categoryIds = $product->getCategoryIds();

			if(count($categoryIds)) {
                /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */
                $collection = Mage::getModel('catalog/category')->getCollection();
				$collection->addAttributeToSelect('name');
				$collection->addAttributeToFilter('is_active', array('eq'=>'1'));
				$collection->addAttributeToFilter('entity_id', array('in' => $categoryIds));
				$collection->addAttributeToSort('entity_id', 'desc');
				//$collection->setPageSize(1);

                /* @var $category Mage_Catalog_Model_Category */
                $category = $collection->getFirstItem();
				if ($category->getId()) {
					$product->setCategory($category);
					Mage::register('current_category', $category);
				}
			}
		}

		return $this;
	}
}
3 REPLIES 3

Re: Full Path Breadcrumbs

its pretty good, code is clean. why did you comment out setPageSize ?

Re: Full Path Breadcrumbs

Good catch.  I'm not sure why it was commented out.  I've un-commented that section and it is working as it was.

Re: Full Path Breadcrumbs


jsmiller wrote:

i'm curious if it will slow down our site at all...


There is additional processing, but it seems pretty negligible with nothing egregious from a performance standpoint (e.g. looped queries). Ultimately you should profile the effects and answer this question yourself.


jsmiller wrote:

is [there] anything that we need to change?


This observer does not handle the case when a product belongs to multiple categories. This may either not be a factor or not be important - you'll decide that based on your requirements.

-----
@benmarks, Senior Manager, Strategy & Growth