Skip to content

Commit e69335c

Browse files
committed
Improved logic to skip other non-category page links
1 parent fa250f5 commit e69335c

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/breadcrumbs.phtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ $viewModel = $block->getData('viewModel');
99
?>
1010
<div class="breadcrumbs" data-mage-init='{
1111
"breadcrumbs": {
12-
"baseUrl": "<?= $block->getBaseUrl(); ?>",
1312
"categoryUrlSuffix": "<?= $block->escapeHtml($viewModel->getCategoryUrlSuffix()); ?>",
1413
"useCategoryPathInUrl": <?= (int)$viewModel->isCategoryUsedInProductUrl(); ?>,
1514
"product": "<?= $block->escapeHtml($viewModel->getProductName()); ?>"

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

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

1414
$.widget('mage.breadcrumbs', widget, {
1515
options: {
16-
baseUrl: '',
16+
categoryPathRegex: /(nav\-)[0-9]+(\-[0-9]+)+/gi,
1717
categoryUrlSuffix: '',
1818
useCategoryPathInUrl: false,
1919
product: '',
@@ -137,7 +137,7 @@ define([
137137
}
138138

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

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

169170
if (categoryUrl && menu.length) {
170171
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+
}
171181
}
172182

173183
return categoryMenuItem;
@@ -194,11 +204,6 @@ define([
194204
if (categoryUrl.indexOf('?') > 0) {
195205
categoryUrl = categoryUrl.substr(0, categoryUrl.indexOf('?'));
196206
}
197-
198-
// prevent double home link, when menu has link to the home
199-
if (categoryUrl === this.options.baseUrl) {
200-
categoryUrl = '';
201-
}
202207
}
203208

204209
return categoryUrl;

0 commit comments

Comments
 (0)