1

I have been facing one issue with breadcrumbs in Magento 2.2.3 CE i.e As per our observation, when the user browses the product from the category page, for some products breadcrumb full path is displaying on the view page.

home -> main category -> sub category -> Name of the product

https://prnt.sc/m5sly9

For some products product name only displaying home -> Name of the product

https://prnt.sc/m5smah

Can anyone please suggest and know the reason why it is happening?

5
  • Do you wants to display category name in breadcrumbs or only wants to display product name?
    – Ronak
    Jan 16, 2019 at 5:58
  • display category full path Jan 16, 2019 at 6:21
  • @NagarajuKasa Are you able to show breadcrumbs with category names on product detail page ? May 24, 2019 at 8:26
  • @sumeetbajaj actually i have been facing this issue with the varnish cache on my dev instance. May 24, 2019 at 8:56
  • @NagarajuKasa ok May 24, 2019 at 8:59

2 Answers 2

2

Go to Admin > Stores > Configuration > Catalog > Catalog > Search Engine Optimization > Set "Yes" for Use Categories Path for Product URLs option.

enter image description here

You need to reindex after configure this setting and need to flush cache.

Please check and accept the answer if it's helpful.

Now add below code just after body tag in catalog_product_view.xml

<referenceBlock name="breadcrumbs" template="Magento_Theme::html/breadcrumbs.phtml"></referenceBlock>

Now just override below file into your current theme.

vendor/magento/module-theme/view/frontend/templates/html/breadcrumbs.phtml

Clean cache after that and check again.

5
  • I have updated my answer please check that.
    – Ronak
    Jan 16, 2019 at 6:48
  • @NagarajuKasa, Have you tried my answer?
    – Ronak
    Jan 16, 2019 at 8:43
  • could you please look into these scenarios Scenario 1: From any page, go to All Products > click on any category > click on any product Scenario 2: From any page, go to Brands > click on any brand > click on any product Scenario 3: Click on any of the products from a Google search to be brought to the product page Jan 17, 2019 at 3:48
  • We have verified this issue and understood that breadcrumbs may potentially being cached. we disabled magento cache and found that it seems working fine. can u please advise any solution for this? drive.google.com/file/d/1mcsj2q6TfwKozrM7XgMsf77heDK7Enm6/view Jan 18, 2019 at 4:34
  • Hi @NagarajuKasa This link is helped for me regarding customjs: magento.stackexchange.com/questions/264496/… Mar 7, 2019 at 7:39
0

Before, first perform two things.

  1. Open product URL directly in Prviate window. You see home -> Name of the product)
  2. Open same product page via Product List page (Category Page). You see home -> main category -> sub category -> Name of the product

Now have a look at this file: \vendor\magento\module-catalog\Helper\Data.php

public function getCategory()
{
    return $this->_coreRegistry->registry('current_category');
}

so if we visit a product page for the first time (clean browser and magento cache). We will have that breadcrumbs empty because registry('current_category') was not set.

If we visit product page after visiting its category, breadcrumbs will be added, because registry('current_category') was set now.

4
  • thanks for your information @akhil gupta, Here when i browse from the list page for some products full path displaying. for some products displaying only product name... but i need to display bread crumbs full path... Jan 16, 2019 at 6:25
  • could u please our customer scenarios Scenario 1: From any page, go to All Products > click on any category > click on any product Scenario 2: From any page, go to Brands > click on any brand > click on any product Scenario 3: Click on any of the products from a Google search to be brought to the product page Jan 17, 2019 at 3:47
  • 1
    @NagarajuKasa, So you want full category path in all product pages, you can make changes in function getBreadcrumbPath() in file \vendor\magento\module-catalog\Helper\Data.php by rewriting in your custom module. You need to get current product then all associated categories the push to the breadcrumb path. Jan 17, 2019 at 4:28
  • can you please let me know is this default magento 2 issue. ? i read some articles regarding this, i am not sure. we are using 2.2.3 CE version Jan 17, 2019 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.