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

FFWEB-2109: Change page parameter in canonical links after changing page #338

Draft
wants to merge 1 commit into
base: release/2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
## Unreleased
### Added
- Add possibility to select field to be exported as numerical in module configuration. Numerical fields will be exported in new multi-attribute column `NumericalAttributes`

- Changing page is now update the page parameter in the canonical link (meta rel="canonical")

## [v2.1.0] - 2021.07.15
### Added
- Add possibility to export fields from variant level. Previously export took only configurable attributes from variants and rest was copied from parent
Expand Down
11 changes: 10 additions & 1 deletion src/view/frontend/templates/ff/communication.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ $parameters = $viewModel->getParameters((array) $block->getData('communication_p
<ff-communication<?php foreach ($parameters as $key => $value) /* @noEscape */ echo sprintf(' %s="%s"', $key, $block->escapeHtmlAttr($value)) ?>></ff-communication>
<!-- Set FieldRoles -->
<script>
document.addEventListener('ffReady', function () {
document.addEventListener('ffReady', function (ff) {
factfinder.communication.fieldRoles = <?= /* @noEscape */ $viewModel->getFieldRoles() ?>;
ff.resultDispatcher.addCallback('paging', function(pageData){
const canonicalLink = document.querySelector('link[rel="canonical"]');
const urlPattern = new RegExp("page=([0-9]*)");
if (canonicalLink && window.location.href.match(urlPattern) !== null) {
canonicalLink.href = canonicalLink.href.match(urlPattern) !== null
? canonicalLink.href.replace(urlPattern, 'page=' + pageData.currentPage)
: canonicalLink.href + '?page=' + pageData.currentPage;
}
});
});
</script>
<script type="text/x-magento-init">
Expand Down