Magento – Magento 2.2 – Breadcrumbs issue

breadcrumbscategorymagento2magento2.2

Currently i've got products in a category sub of default for example:

Root -> Sub cat -> product

I've noticed that on the product page itself the breadcrumbs are working fine for some products and not for others. Some products will show the category and others wont show the category in the breadcrumb, they will either not show the category or they will show the category.

Something else i have come across is if I currently don't assign the product to default cat the following happens:

The product is assigned to default cat

The product has a sort order of 0 in the category list

The breadcrumbs don't show the category.

What is going on? Why is the breadcrumb breaking when it is either assigned to this Default cat ( which is the root cat btw ) and I don't get what is happening with the products where the category isn't being shown in the breadcrumb.

Magento is on 2.2 – I've reindexed – I've flushed cache.

I've also pulled all of my hair out – no just a joke.

* EDIT *

If anyone is having this issue, Full page cache is the culprit – disable this, flush cache and it should work how it is required.

Best Answer

NO, the full page cache is not the culprit.

DON'T DISABLE FULL PAGE CACHE.

The logic flow is clearly described in \Magento\Catalog\Helper\Data::getBreadcrumbPath() when it runs $category = $this->getCategory().

Just see the getCategory() code

/**
 * Return current category object
 *
 * @return \Magento\Catalog\Model\Category|null
 */
public function getCategory()
{
    return $this->_coreRegistry->registry('current_category');
}

It returns an object saved in the registry called current_category. If the object is not present, the breadcrumbs will be empty.

For example, if you make a first time access (clean browser and magento cache) to a product directly from search box, you will have that breadcrumbs will be empty because registry('current_category') was not setted.

Otherwise, if you make a first time access (clean browser and magento cache) to a product after visited its category, breadcrumbs will be present, because registry('current_category') was setted.

Then, every time you make a second visit to same product page you just see the same result, because FPC (FULL PAGE CACHE) JUST CACHE EVERY GET REQUEST AND RESPONSE WITH THE CONTENT OF THE FIRST TIME VISIT.

Related Topic