Skip to content

Commit 1df8452

Browse files
committed
Use 'category-item' links only.
This change prevents adding custom links, like 'contacts', 'home', etc.into breadcrumbs
1 parent e69335c commit 1df8452

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

app/code/Magento/Catalog/Plugin/Block/Topmenu.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ private function getCategoryAsArray($category, $currentCategory, $isParentActive
162162
'url' => $this->catalogCategory->getCategoryUrl($category),
163163
'has_active' => in_array((string)$category->getId(), explode('/', $currentCategory->getPath()), true),
164164
'is_active' => $category->getId() == $currentCategory->getId(),
165+
'is_category' => true,
165166
'is_parent_active' => $isParentActive
166167
];
167168
}

app/code/Magento/Catalog/view/frontend/web/js/product/breadcrumbs.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ define([
1313

1414
$.widget('mage.breadcrumbs', widget, {
1515
options: {
16-
categoryPathRegex: /(nav\-)[0-9]+(\-[0-9]+)+/gi,
1716
categoryUrlSuffix: '',
1817
useCategoryPathInUrl: false,
1918
product: '',
19+
categoryItemSelector: '.category-item',
2020
menuContainer: '[data-action="navigation"] > ul'
2121
},
2222

@@ -137,7 +137,7 @@ define([
137137
}
138138

139139
classes = menuItem.parent().attr('class');
140-
classNav = classes.match(this.options.categoryPathRegex);
140+
classNav = classes.match(/(nav\-)[0-9]+(\-[0-9]+)+/gi);
141141

142142
if (classNav) {
143143
classNav = classNav[0];
@@ -164,20 +164,13 @@ define([
164164
_resolveCategoryMenuItem: function () {
165165
var categoryUrl = this._resolveCategoryUrl(),
166166
menu = $(this.options.menuContainer),
167-
categoryMenuItem = null,
168-
isCategoryMenuItem;
167+
categoryMenuItem = null;
169168

170169
if (categoryUrl && menu.length) {
171-
categoryMenuItem = menu.find('a[href="' + categoryUrl + '"]');
172-
173-
// Check if this is a category (Not a link to contacts, homepage, etc)
174-
isCategoryMenuItem = categoryMenuItem.parent('li')
175-
.attr('class')
176-
.match(this.options.categoryPathRegex);
177-
178-
if (!isCategoryMenuItem) {
179-
categoryMenuItem = null;
180-
}
170+
categoryMenuItem = menu.find(
171+
this.options.categoryItemSelector +
172+
' > a[href="' + categoryUrl + '"]'
173+
);
181174
}
182175

183176
return categoryMenuItem;

app/code/Magento/Theme/Block/Html/Topmenu.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ protected function _getMenuItemClasses(\Magento\Framework\Data\Tree\Node $item)
309309
$classes[] = 'level' . $item->getLevel();
310310
$classes[] = $item->getPositionClass();
311311

312+
if ($item->getIsCategory()) {
313+
$classes[] = 'category-item';
314+
}
315+
312316
if ($item->getIsFirst()) {
313317
$classes[] = 'first';
314318
}

0 commit comments

Comments
 (0)