Skip to content

Commit 5157bef

Browse files
ENGCOM-6645: SEO: Do not follow links on filter options #26213
- Merge Pull Request #26213 from paveq/magento2:fix/filter_seo_indexing - Merged commits: 1. 66502c8 2. 29635cc 3. 5422eb9 4. c4ffa89 5. 76946a6 6. 256a845
2 parents 3811867 + 256a845 commit 5157bef

File tree

5 files changed

+91
-27
lines changed

5 files changed

+91
-27
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\LayeredNavigation\ViewModel\Layer;
8+
9+
use Magento\Catalog\Helper\Data as DataHelper;
10+
use Magento\Framework\View\Element\Block\ArgumentInterface;
11+
12+
/**
13+
* ViewModel for Product Layer
14+
*/
15+
class Filter implements ArgumentInterface
16+
{
17+
/**
18+
* @var DataHelper
19+
*/
20+
private $dataHelper;
21+
22+
/**
23+
* Constructor
24+
*
25+
* @param DataHelper $dataHelper
26+
*/
27+
public function __construct(DataHelper $dataHelper)
28+
{
29+
$this->dataHelper = $dataHelper;
30+
}
31+
32+
/**
33+
* Check is should display product count on layer
34+
*
35+
* @return bool
36+
*/
37+
public function shouldDisplayProductCountOnLayer(): bool
38+
{
39+
return $this->dataHelper->shouldDisplayProductCountOnLayer();
40+
}
41+
}

app/code/Magento/LayeredNavigation/view/frontend/layout/catalog_category_view_type_layered.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
<referenceContainer name="sidebar.main">
1212
<block class="Magento\LayeredNavigation\Block\Navigation\Category" name="catalog.leftnav" before="-" template="Magento_LayeredNavigation::layer/view.phtml">
1313
<block class="Magento\LayeredNavigation\Block\Navigation\State" name="catalog.navigation.state" as="state" />
14-
<block class="Magento\LayeredNavigation\Block\Navigation\FilterRenderer" name="catalog.navigation.renderer" as="renderer" template="Magento_LayeredNavigation::layer/filter.phtml"/>
14+
<block class="Magento\LayeredNavigation\Block\Navigation\FilterRenderer" name="catalog.navigation.renderer" as="renderer" template="Magento_LayeredNavigation::layer/filter.phtml">
15+
<arguments>
16+
<argument name="product_layer_view_model" xsi:type="object">Magento\LayeredNavigation\ViewModel\Layer\Filter</argument>
17+
</arguments>
18+
</block>
1519
</block>
1620
</referenceContainer>
1721
</body>

app/code/Magento/LayeredNavigation/view/frontend/layout/catalogsearch_result_index.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
<referenceContainer name="sidebar.main">
1212
<block class="Magento\LayeredNavigation\Block\Navigation\Search" name="catalogsearch.leftnav" before="-" template="Magento_LayeredNavigation::layer/view.phtml">
1313
<block class="Magento\LayeredNavigation\Block\Navigation\State" name="catalogsearch.navigation.state" as="state" />
14-
<block class="Magento\LayeredNavigation\Block\Navigation\FilterRenderer" name="catalogsearch.navigation.renderer" as="renderer" template="Magento_LayeredNavigation::layer/filter.phtml"/>
14+
<block class="Magento\LayeredNavigation\Block\Navigation\FilterRenderer" name="catalogsearch.navigation.renderer" as="renderer" template="Magento_LayeredNavigation::layer/filter.phtml">
15+
<arguments>
16+
<argument name="product_layer_view_model" xsi:type="object">Magento\LayeredNavigation\ViewModel\Layer\Filter</argument>
17+
</arguments>
18+
</block>
1519
</block>
1620
</referenceContainer>
1721
</body>

app/code/Magento/LayeredNavigation/view/frontend/templates/layer/filter.phtml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@
77
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
88
?>
99
<?php
10-
/**
11-
* Template for filter items block
12-
*
13-
* @var $block \Magento\LayeredNavigation\Block\Navigation\FilterRenderer
14-
*/
10+
/** @var $block \Magento\LayeredNavigation\Block\Navigation\FilterRenderer */
11+
/** @var \Magento\LayeredNavigation\ViewModel\Layer\Filter $viewModel */
12+
$viewModel = $block->getData('product_layer_view_model');
1513
?>
1614

1715
<ol class="items">
18-
<?php foreach ($filterItems as $filterItem) : ?>
16+
<?php foreach ($filterItems as $filterItem): ?>
1917
<li class="item">
20-
<?php if ($filterItem->getCount() > 0) : ?>
21-
<a href="<?= $block->escapeUrl($filterItem->getUrl()) ?>">
18+
<?php if ($filterItem->getCount() > 0): ?>
19+
<a href="<?= $block->escapeUrl($filterItem->getUrl()) ?>" rel="nofollow">
2220
<?= /* @noEscape */ $filterItem->getLabel() ?>
23-
<?php if ($this->helper(\Magento\Catalog\Helper\Data::class)->shouldDisplayProductCountOnLayer()) : ?>
24-
<span class="count"><?= /* @noEscape */ (int)$filterItem->getCount() ?><span class="filter-count-label">
25-
<?php if ($filterItem->getCount() == 1) :
21+
<?php if ($viewModel->shouldDisplayProductCountOnLayer()): ?>
22+
<span class="count"><?= /* @noEscape */ (int)$filterItem->getCount() ?>
23+
<span class="filter-count-label">
24+
<?php if ($filterItem->getCount() == 1):
2625
?> <?= $block->escapeHtml(__('item')) ?><?php
27-
else :
26+
else:
2827
?> <?= $block->escapeHtml(__('item')) ?><?php
2928
endif;?></span></span>
3029
<?php endif; ?>
3130
</a>
32-
<?php else :?>
31+
<?php else: ?>
3332
<?= /* @noEscape */ $filterItem->getLabel() ?>
34-
<?php if ($this->helper(\Magento\Catalog\Helper\Data::class)->shouldDisplayProductCountOnLayer()) : ?>
35-
<span class="count"><?= /* @noEscape */ (int)$filterItem->getCount() ?><span class="filter-count-label">
36-
<?php if ($filterItem->getCount() == 1) :
33+
<?php if ($viewModel->shouldDisplayProductCountOnLayer()): ?>
34+
<span class="count"><?= /* @noEscape */ (int)$filterItem->getCount() ?>
35+
<span class="filter-count-label">
36+
<?php if ($filterItem->getCount() == 1):
3737
?><?= $block->escapeHtml(__('items')) ?><?php
38-
else :
38+
else:
3939
?><?= $block->escapeHtml(__('items')) ?><?php
4040
endif;?></span></span>
4141
<?php endif; ?>

app/code/Magento/Swatches/view/frontend/templates/product/layered/renderer.phtml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
attribute-code="<?= $block->escapeHtmlAttr($swatchData['attribute_code']) ?>"
1515
attribute-id="<?= $block->escapeHtmlAttr($swatchData['attribute_id']) ?>">
1616
<div class="swatch-attribute-options clearfix">
17-
<?php foreach ($swatchData['options'] as $option => $label) : ?>
18-
<a href="<?= $block->escapeUrl($label['link']) ?>"
17+
<?php foreach ($swatchData['options'] as $option => $label): ?>
18+
<a href="<?= $block->escapeUrl($label['link']) ?>" rel="nofollow"
1919
aria-label="<?= $block->escapeHtmlAttr($label['label']) ?>"
2020
class="swatch-option-link-layered">
21-
<?php if (isset($swatchData['swatches'][$option]['type'])) : ?>
21+
<?php if (isset($swatchData['swatches'][$option]['type'])): ?>
2222
<?php switch ($swatchData['swatches'][$option]['type']) {
2323
case '3':
2424
?>
@@ -33,16 +33,27 @@
3333
<?php break;
3434
case '2':
3535
?>
36-
<?php $swatchThumbPath = $block->getSwatchPath('swatch_thumb', $swatchData['swatches'][$option]['value']); ?>
37-
<?php $swatchImagePath = $block->getSwatchPath('swatch_image', $swatchData['swatches'][$option]['value']); ?>
36+
<?php $swatchThumbPath = $block->getSwatchPath(
37+
'swatch_thumb',
38+
$swatchData['swatches'][$option]['value']
39+
); ?>
40+
<?php $swatchImagePath = $block->getSwatchPath(
41+
'swatch_image',
42+
$swatchData['swatches'][$option]['value']
43+
);
44+
$escapedUrl = $block->escapeUrl($swatchImagePath);
45+
?>
3846
<div class="swatch-option image <?= $block->escapeHtmlAttr($label['custom_style']) ?>"
3947
tabindex="-1"
4048
option-type="2"
4149
option-id="<?= $block->escapeHtmlAttr($option) ?>"
4250
option-label="<?= $block->escapeHtmlAttr($label['label']) ?>"
4351
option-tooltip-thumb="<?= $block->escapeUrl($swatchThumbPath) ?>"
4452
option-tooltip-value=""
45-
style="background: url(<?= $block->escapeUrl($swatchImagePath) ?>) no-repeat center; background-size: initial;"></div>
53+
style="background: url(<?=
54+
/* @noEscape */ $escapedUrl
55+
?>) no-repeat center; background-size: initial;">
56+
</div>
4657
<?php break;
4758
case '1':
4859
?>
@@ -52,8 +63,12 @@
5263
option-id="<?= $block->escapeHtmlAttr($option) ?>"
5364
option-label="<?= $block->escapeHtmlAttr($label['label']) ?>"
5465
option-tooltip-thumb=""
55-
option-tooltip-value="<?= $block->escapeHtmlAttr($swatchData['swatches'][$option]['value']) ?>"
56-
style="background: <?= $block->escapeHtmlAttr($swatchData['swatches'][$option]['value']) ?> no-repeat center; background-size: initial;"></div>
66+
option-tooltip-value="<?= $block->escapeHtmlAttr(
67+
$swatchData['swatches'][$option]['value']
68+
) ?>"
69+
style="background: <?= $block->escapeHtmlAttr(
70+
$swatchData['swatches'][$option]['value']
71+
) ?> no-repeat center; background-size: initial;"></div>
5772
<?php break;
5873
case '0':
5974
default:

0 commit comments

Comments
 (0)