Magento – is there a way to get Breadcrumbs to display correct information

breadcrumbs

when you navigate to an item that was in a 3rd level category, if you copy that url and go to a completely different product in a completely different 3rd level category and then paste in the URL you copied only the product name in the breadcrumbs is updated, the category path wont change

ie
go to Men's, Clothing, Coats, Men's Coat 1, the Breadcumbs will say something like "Home > Men's > Clothing > Coats > Men's Coat 1",

copy the URL than go to Women's, Footwear, Heels, Women's Heel 1, the breadcrumb will be "Home > Women's > Footwear> Heels > Women's Heel 1"

Now if you paste the URL you copied from the Coat, the Breadcrumbs will be "Home > Women's > Footwear> Heels > Men's Coat 1" which isn't correct

i set up a clean build of magento without any of the extensions and duplicated the test and it did the same so it's obviously a problem with magento, i'm wondering if there already exists a way to fix this

UPDATE: my current solution that i am using now is to rebuild the breadcrumbs when a customer enters the product view which is hardly efficient so i still want to know if there is a better why

Best Answer

Now if you paste the URL you copied from the Coat, the Breadcrumbs will be "Home > Women's > Footwear> Heels > Men's Coat 1" which isn't correct

In my experience this is local to 1.11EE - This is due to the fact that Magento uses the cookie value from LAST_CATEGORY. I requested a patch from EE support for this and they provided one to me. I'd be surprised if this wasn't fixed in 1.12.

While I don't have the patchfile at the moment, an SVN diff yielded the following:

Index: app/code/core/Enterprise/PageCache/Model/Processor/Default.php
===================================================================
--- app/code/core/Enterprise/PageCache/Model/Processor/Default.php  (revision 717)
+++ app/code/core/Enterprise/PageCache/Model/Processor/Default.php  (revision 718)
@@ -103,6 +103,7 @@
          */
         if ($container && !Mage::getIsDeveloperMode()) {
             $container = new $container($this->_placeholder);
+            $container->setProcessor(Mage::getSingleton('enterprise_pagecache/processor'));
             $blockContent = $matches[1];
             $container->saveCache($blockContent);
         }
Index: app/code/core/Enterprise/PageCache/Model/Container/Breadcrumbs.php
===================================================================
--- app/code/core/Enterprise/PageCache/Model/Container/Breadcrumbs.php  (revision 717)
+++ app/code/core/Enterprise/PageCache/Model/Container/Breadcrumbs.php  (revision 718)
@@ -51,6 +51,10 @@
     protected function _renderBlock()
     {
         $productId = $this->_getProductId();
+
+        /** @var $product null|Mage_Catalog_Model_Product */
+        $product = null;
+
         if ($productId) {
             $product = Mage::getModel('catalog/product')
                 ->setStoreId(Mage::app()->getStore()->getId())
@@ -60,6 +64,12 @@
             }
         }
         $categoryId = $this->_getCategoryId();
+
+        if ($product !== null && !$product->canBeShowInCategory($categoryId)) {
+            $categoryId = null;
+            Mage::unregister('current_category');
+        }
+
         if ($categoryId && !Mage::registry('current_category')) {
             $category = Mage::getModel('catalog/category')->load($categoryId);
             if ($category) {
@@ -68,7 +78,7 @@
         }

         //No need breadcrumbs on CMS pages
-        if (!$categoryId) {
+        if (!$productId && !$categoryId) {
             return '';
         }

Index: app/code/core/Enterprise/PageCache/Model/Observer.php
===================================================================
--- app/code/core/Enterprise/PageCache/Model/Observer.php   (revision 717)
+++ app/code/core/Enterprise/PageCache/Model/Observer.php   (revision 718)
@@ -546,6 +546,10 @@
      */
     public function updateProductInfo(Varien_Event_Observer $observer)
     {
+        if (!$this->isCacheEnabled()) {
+            return $this;
+        }
+
         $paramsObject = $observer->getEvent()->getParams();
         if ($paramsObject instanceof Varien_Object) {
             if (array_key_exists(Enterprise_PageCache_Model_Cookie::COOKIE_CATEGORY_ID, $_COOKIE)) {
Index: app/code/core/Mage/Catalog/Helper/Product.php
===================================================================
--- app/code/core/Mage/Catalog/Helper/Product.php   (revision 717)
+++ app/code/core/Mage/Catalog/Helper/Product.php   (revision 718)
@@ -307,6 +307,8 @@
             if ($product->canBeShowInCategory($lastId)) {
                 $categoryId = $lastId;
             }
+        } elseif (!$product->canBeShowInCategory($categoryId)) {
+            $categoryId = null;
         }

         if ($categoryId) {
@@ -322,9 +324,7 @@
         try {
             Mage::dispatchEvent('catalog_controller_product_init', array('product' => $product));
             Mage::dispatchEvent('catalog_controller_product_init_after',
-                            array('product' => $product,
-                                'controller_action' => $controller
-                            )
+                array('product' => $product, 'controller_action' => $controller)
             );
         } catch (Mage_Core_Exception $e) {
             Mage::logException($e);
Related Topic