Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with breadcrumbs #7967

Closed
susmithaN opened this issue Dec 27, 2016 · 50 comments
Closed

Problems with breadcrumbs #7967

susmithaN opened this issue Dec 27, 2016 · 50 comments
Labels
bug report Component: Catalog Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@susmithaN
Copy link

susmithaN commented Dec 27, 2016

Preconditions

I have some problems with breadcrumbs .
Im using

  1. Magento ver. 2.1.1
  2. PHP Version 7.1.0

Steps to reproduce

  1. Open Product from list page
    List page - http://prnt.sc/doeoxy

Expected result

  1. details page should contain breadcrumbs in this format Home -> Category name ->Product Name

    Home > Proteasome Inhibitors > MG-132

Actual result

  1. Home > MG-132 - Category missing
    Detail page - http://prnt.sc/doeqa2

Is it possible to get full breadcrumb with Magento 2 ?

@veloraven
Copy link
Contributor

@susmithaN thank you for your submission.
Please add exact steps how to reproduce the issue to the Steps section, without links to external resources.

@susmithaN
Copy link
Author

Hi ,

Steps to reproduce

1 . GO to category page (product list page ) from home page .
2 . From category page to product detail page .
3 . On product detail page , breadcrumbs looks like Home > Product name
But the expected result is Home > category name > product name

@yumicom
Copy link

yumicom commented Jan 5, 2017

I have same problem. How to display breadcrumbs with full path on product view pages?

@ghost
Copy link

ghost commented Jan 5, 2017

Same issue on CE 2.1.3

@veloraven
Copy link
Contributor

We have created internal ticket MAGETWO-63011

@veloraven veloraven added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Jan 6, 2017
@susmithaN
Copy link
Author

Hi , Kindly let us know if any updates regarding this issue .

@susmithaN
Copy link
Author

Is there any updates regarding this issue ?

@susmithaN
Copy link
Author

Anyone have any idea about this issue ?

@ghost
Copy link

ghost commented Feb 8, 2017

Just made an update to version 2.1.4 via web wizard, still got those broken breadcrumbs.

@susmithaN
Copy link
Author

Hi ,
I have checked this issue on Latest version , There also i faced the same breadcrumbs issues. I Found an option to add category with product url from back end . Once enabled it Breadcrumbs with category displayed on product detail page . But If I open the same product from any other page like home , search , its not displaying full breadcrumbs . Just showing Home-> product name . Can you please suggest any solution for this .

@orlangur
Copy link
Contributor

PHP Version 7.1.0

Is it correct? This PHP version is not supported yet.

Is issue reproducible when you disable caches?

@ghost
Copy link

ghost commented Feb 20, 2017

I am on PHP Version 5.3.6 and Magento 2 Version 2.1.4. Issue occures even with cache disabled. Dev and production mode are equally affected.

@susmithaN
Copy link
Author

Hi , Anyone have any suggestion to solve this issue .

@susmithaN
Copy link
Author

Hi , Please let me know if you have any suggestion regarding this issue.

@akosglue
Copy link

Hi @susmithaN , disclaimer: this is just an idea for a workaround and not yet tested completely, but maybe you can get a hint from it:

  • if you override _prepareLayout() in \Magento\Catalog\Block\Breadcrumbs in your custom module
  • add this in the beginning:
    $product = $this->registry->registry('current_product'); if($product != null){ $cats = $prod->getAvailableInCategories(); end($cats); $last = prev($cats); $categ = $this->_repository->get($last); $this->registry->register('current_category',$categ, true); }
    This basically adds the missing category 'manually' to the registry.

@susmithaN
Copy link
Author

Hi , Thank you for your information . I tried this one . But Still got the same problem . I cant able to add missing categories on registry .

@susmithaN
Copy link
Author

Hi , Any other suggestion to solve this problem .

@sambolek
Copy link
Contributor

sambolek commented Apr 1, 2017

This was the case in M1 as well, if you had "Use category path for product URL" set to "No" https://www.creare.co.uk/wp-content/uploads/2014/03/fdf-2-658x328.jpg

Only with category path in URL, Magento could resolve which category should be in breadcrumbs path. This sure is unfortunate, but don't believe it's a bug, as we cannot simply guess what category to show at the top, unless we add some sort of query parameter to URL that would identify which category the product was accessed from.

@orlangur
Copy link
Contributor

orlangur commented Apr 1, 2017

we cannot simply guess what category to show at the top, unless we add some sort of query parameter to URL

If a product belongs to only one category, we can use it in breadcrumbs. However, if in this issue Use category path for product URL = "No" it would be not correct to change breadcrumbs this way as breadcrumbs should reflect site navigation, not some random stuff.

@sambolek
Copy link
Contributor

sambolek commented Apr 1, 2017

Exactly.
I'm thinking that having inconsistent breadcrumbs, where we show a category path if product is in only one caregory, and nothing (or random/last assigned category) if it's in multiple categories would be more hurtful than this.

Presume we have two choices here:

  1. Leave it as is, but maybe describe in documentation what are the consequences of setting "Use category path for product URL" to " No"
  2. Figure out a way of implementing history-based breadcrumbs that work with Varnish/FPC (there were some M1 extensions that relied to HTTP referrer, but that would introduce another layer of problems with caching)

To conclude, this is more of a feature request than a bug report.

@susmithaN
Copy link
Author

Thank you for the information ,

@ghost
Copy link

ghost commented May 13, 2017

but don't believe it's a bug, as we cannot simply guess what category to show at the top, unless we add some sort of query parameter to URL that would identify which category the product was accessed from.

Fine but why do I sometimes get a full breadcrumb when I follow my category up to the product from the front page and sometimes not? That makes no sense.

@MattSewing
Copy link

Totally agree with salacis

I have the same problem, one moment i have full category path - the next i don't.

Sometimes I can have the full path in the breadcrumb, 5 mins later I can refresh the page, and it changes.

@mbahar
Copy link

mbahar commented Jun 22, 2017

As a solution;
To override the inconsistent behaviour, I override the block;
Magento\Catalog\Block\Breadcrumbs

with the following;
https://gist.github.com/mbahar/82703c4b95d924d9bc8e6990202fdeba

@BigTonni
Copy link

I have a same issue with 2.1.6. Still looking for a solution.

@jonahellison
Copy link

jonahellison commented Dec 13, 2017

Breadcrumbs use catalog session data (the last category the user viewed) for rendering, which seems to be a flaw since this is then cached and displayed to other users.

One workaround is to use another event observer (such as layout_load_before) along with #7967 (comment) to remove this data:

        // @var \Magento\Catalog\Model\Session $catalogSession
        $this->catalogSession
            ->unsetData('last_visited_category_id')
            ->unsetData('last_viewed_category_id');

@magefan
Copy link
Contributor

magefan commented Jan 20, 2018

Based on @novakivskiy suggestion we have created a temporary solution magefan/module-catalog.

You can simply install it via composer

@elvinristi
Copy link
Contributor

I'm using this in following way so this doesn't affect performance - don't load unnecessary objects :

File contents for etc/module.xml :

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_MyModuleName" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Catalog"/>
        </sequence>
    </module>
</config>

File contents for etc/frontend/events.xml :

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="catalog_controller_product_init_after">
        <observer instance="Vendor\MyModuleName\Observer\Catalog\Product\InitAfter" name="execute"/>
    </event>
</config>

File contents for Observer/Catalog/Product/InitAfter.php :

<?php

namespace Vendor\MyModuleName\Observer\Catalog\Product;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;

class InitAfter implements \Magento\Framework\Event\ObserverInterface
{
    const LEVEL_LARGER_THAN = 2;

    /**
     * @var \Magento\Framework\Registry
     */
    private $registry;

    /**
     * @var \Magento\Catalog\Api\CategoryRepositoryInterface
     */
    private $categoryRepository;

    /**
     * @var ScopeConfigInterface
     */
    private $scopeConfig;

    /**
     * @var \Magento\Framework\App\ResourceConnection
     */
    private $resource;

    /**
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    private $storeManager;

    /**
     * @var \Magento\Framework\DB\Adapter\AdapterInterface
     */
    private $connection;

    public function __construct(
        \Magento\Framework\Registry $registry,
        \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository,
        ScopeConfigInterface $scopeConfig,
        \Magento\Framework\App\ResourceConnection $resource,
        \Magento\Store\Model\StoreManagerInterface $storeManager
    ) {
        $this->registry = $registry;
        $this->categoryRepository = $categoryRepository;
        $this->scopeConfig = $scopeConfig;

        $this->resource = $resource;
        $this->storeManager = $storeManager;
    }

    /**
     * Execute observer
     *
     * @param \Magento\Framework\Event\Observer $observer
     *
     * @return void
     */
    public function execute(
        \Magento\Framework\Event\Observer $observer
    ) {
        /** @var \Magento\Catalog\Model\Product $currentProduct */
        $currentProduct  = $observer->getEvent()->getProduct();
        /** @var \Magento\Catalog\Model\Category $currentCategory */
        $currentCategory = $this->registry->registry('current_category');

        $categoryIds = (array)$currentProduct->getAvailableInCategories();

        if ($currentCategory !== null
            && in_array($currentCategory->getId(), $categoryIds)
            && array_search($currentCategory->getId(), $categoryIds) === 0
        ) {
            return;
        }

        if (empty($categoryIds)) {
            return;
        }

        $connection = $this->resource->getConnection();

        $categoryId = $connection->fetchOne(
            $connection->select()->from(
                $this->resource->getTableName('catalog_category_product_index'), 'category_id'
            )->join(
                array('ce' => $this->resource->getTableName('catalog_category_entity')), 'ce.entity_id = category_id', array()
            )->where(
                'product_id = ?', $currentProduct->getId()
            )->where(
                'store_id = ?', $this->storeManager->getStore()->getId()
            )->where(
                'is_parent = 1'
            )->where(
                'category_id IN (?)', $categoryIds
            )->where('ce.level > ?', self::LEVEL_LARGER_THAN)
        );

        if (empty($categoryId)) {
            return;
        }

        if ($currentCategory) {
            $this->registry->unregister('current_category');
        }

        try {
            $category = $this->categoryRepository->get($categoryId);
        } catch (NoSuchEntityException $e) {
            $category = null;
        }

        if ($category) {
            $currentProduct->setCategory($category);
            $this->registry->register('current_category', $category, true);
        }
    }
}

@pioneerathletics
Copy link

Has this issue been fixed in any 2.1 version? I am also currently experiencing this in 2.1.10- Products will show home > category > category > product name and then after some time it just shows home > product name.

@subbu1993
Copy link

Hello - @magento-engcom-team

Is there an update on this issue ?

Can we expect a fix anytime soon ?

@sambolek
Copy link
Contributor

sambolek commented Jul 2, 2018

since 2.2.3 breadcrumbs are a JS widget that relies on page referer to get category path https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Catalog/view/frontend/web/js/product/breadcrumbs.js

@orlangur
Copy link
Contributor

orlangur commented Jul 3, 2018

@susmithaN @magento-engcom-team looks like the issue is fixed in 2.2.x.

@MattSewing
Copy link

MattSewing commented Jul 3, 2018 via email

@orlangur
Copy link
Contributor

orlangur commented Jul 3, 2018

@MattSewing,

As the author of this post, I have come to the conclusion a year on, that it cannot be done

Well, any kind of logic can be done :) But without referer and if product can be assigned to more than one category, logic is really not clear to me.

@LucScu
Copy link

LucScu commented Sep 4, 2018

@magento-engcom-team @orlangur please close this issue, because it is not an issue.
It is clear that without a referer or parametrized url is not possible to construct the complete product's breadcrumbs with categories.

@magento-engcom-team magento-engcom-team added Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch and removed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Sep 7, 2018
@magento-engcom-team
Copy link
Contributor

Closing. Thank you

@Yamaha32088
Copy link
Contributor

The problem appears to be a typo in this file

'userCategoryPathInUrl' => (int)$this->isCategoryUsedInProductUrl(),
it should be useCategoryPathInUrl instead because is looking for it

@sidolov
Copy link
Contributor

sidolov commented Feb 8, 2019

Hi @susmithaN. Thank you for your report.
The issue has been fixed in #19760 by @Yamaha32088 in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.9 release.

@sidolov sidolov added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Feb 8, 2019
@robertbaum
Copy link

yes I saw that the issue caused by the cache when someone opens the product from the search or from a custom widget the product page will be opened without category breadcrumbs and as well will be cached as it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Catalog Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests