Magento 2 – Fix Breadcrumb Path from Category Page to Product Description Page

breadcrumbsmagento-2.1magento2

I have a parent category SHOP and in shop, there are products. When I click on products, it goes on product description page. However, breadcrumb shows "home- > product1" instead of "home -> shop -> product1"

Best Answer

Possible Issue

This issue can occur when the full page cache caches a product page when visited from search or directly via the url.

As the breadcrumbs when visited from search do not show the full category path, the page will then be saved in the FPC with the breadcrumbs as Home > Product, even when later visited from a category.

Possible Solution

To overcome this I created a module which takes the deepest category path and uses that for breadcrumbs mainly so that users can see the path when searching for products.

In my case there was never breadcrumbs on products as page cache was warmed up from a sitemap and so similar to searching for products, directly viewing a product from URL showed no breadcrumbs.

This module below however replaces the default breadcrumbs behavior and should show breadcrumbs regardless once installed.

https://github.com/harrigo/EverCrumbs

Issues

This will cause some incorrect paths if product in multiple categories and so will show wrong path for shallower path. This would of been the case in default Magento however depending which page was visited first.

Improvements

This could be improved to overcome the issue of incorrect paths when visited from another shallower category path however never got around to it as products were not listed in multiple categories in my case.

Ideally this needs to be modified to have breadcrumbs hole punched so they are always correct on category pages and then just replace search breadcrumbs with these new breadcrumbs for search.