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

Breadcrumb misordered Randomly #4

Open
nickpiro opened this issue Oct 1, 2019 · 4 comments
Open

Breadcrumb misordered Randomly #4

nickpiro opened this issue Oct 1, 2019 · 4 comments

Comments

@nickpiro
Copy link

nickpiro commented Oct 1, 2019

We're running Magento 2.2.8 currently and we're seeing a weird issue where on some product level pages, the sub-directories ordering is reversed.

For example:
Main Category
-Sub-Category 1
--Sub-Category 2 (Within Sub-Category)
---Product Page

Now, based on this hierarchy, you would assume the breadcrumb on the product page would be:
Main Category > Sub-Category 1 > Sub-Category 2 > Product

But what we see (randomly) is:
Main Category > Sub-Category 2 > Sub-Category 1 > Product

Is there anything that we're missing here?

@svenakela
Copy link

Running 2.2.9 on one server and see the same thing, but only for one specific category and its subcategories. All other categories work as expected.
According to the database, we have correct level order, but looking at the category id, it seems the sorting follows that order. It looks like the ordering is not taking effect and happens to work by luck on all other categories.

@svenakela
Copy link

@nickpiro I added following usort in the file app/code/Harrigo/EverCrumbs/Block/Evercrumbs.php:

        usort($breadcrumbCategories, function ($a, $b) {
            return strcmp($a->getLevel(), $b->getLevel());
        });
        foreach ($breadcrumbCategories as $category) {

It seems to solve the problem, even though we now have two sorts in a row...

@ProgrammerNomad
Copy link

@nickpiro I added following usort in the file app/code/Harrigo/EverCrumbs/Block/Evercrumbs.php:

        usort($breadcrumbCategories, function ($a, $b) {
            return strcmp($a->getLevel(), $b->getLevel());
        });
        foreach ($breadcrumbCategories as $category) {

It seems to solve the problem, even though we now have two sorts in a row...

Thanks for update, now it working fine :)

@kushal9291
Copy link

Had the same issue. This resolved it.

public function getCrumbs()
    {
		$evercrumbs = array();
		
		$evercrumbs[] = array(
			'label' => 'Home',
			'title' => 'Go to Home Page',
			'link' => $this->_storeManager->getStore()->getBaseUrl()
		);
		$path = $this->_catalogData->getBreadcrumbPath();
		$product = $this->registry->registry('current_product');
		$categoryCollection = clone $product->getCategoryCollection();
		$categoryCollection->clear();
		$categoryCollection->addAttributeToSort('level', $categoryCollection::SORT_ORDER_DESC)->addAttributeToFilter('path', array('like' => "1/" . $this->_storeManager->getStore()->getRootCategoryId() . "/%"));
		$categoryCollection->setPageSize(1);
		$breadcrumbCategories = $categoryCollection->getFirstItem()->getParentCategories();
	 
		array_pop($path);
		foreach ($path as $category) {
			$evercrumbs[] = array(
				'label' => $category['label'],
				'title' => $category['label'],
				'link' =>  array_key_exists( 'link', $category) ? $category['link'] : ''
			);
		}
	
		
		$evercrumbs[] = array(
				'label' => $product->getName(),
				'title' => $product->getName(),
				'link' => ''
			); 

		return $evercrumbs;
    }

Not sure though if this is right way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants