Skip to content

Fix: filter clear url #273

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

Open
wants to merge 3 commits into
base: beta
Choose a base branch
from
Open

Fix: filter clear url #273

wants to merge 3 commits into from

Conversation

ah-net
Copy link
Collaborator

@ah-net ah-net commented Apr 23, 2025

This pull request fixes an issue with the clear/remove filter url when using an alp with the same url as the selected filter.

How to reproduce

  • Enable ajax navigation
  • Use seo path slugs for url strategy
  • Make an alp with the same url as an filter + value as part of the url. For example: /merken/4-seasons-outdoor-tuinmeubelen/4-seasons-outdoor-capalbio. This url contains the name of the filter /merken/4-seasons-outdoor.
  • When selecting the filter you get an url like: merken/4-seasons-outdoor-tuinmeubelen/4-seasons-outdoor-capalbio/merken/4-seasons-outdoor/
  • Go remove the filter or click on the clear all filters button.
  • See that the url is not /merken/4-seasons-outdoor-tuinmeubelen/4-seasons-outdoor-capalbio but /-tuinmeubelen/4-seasons-outdoor-capalbio

Because the url contains the filter + value it gets removed. This pull request fixes that. The url part is only removed if it ends with an slash. Or with nothing.

@ah-net ah-net requested a review from jansentjeu April 23, 2025 11:36
Comment on lines +398 to +399
rtrim($currentFilterPath, '/');
$url = str_replace($currentFilterPath . '/', $newFilterPath . '/', $currentUrl);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rtrim is currently doing nothing, because the expression result is not used anywhere.
Use this instead of the two new added lines:

$url = str_replace(
    sprintf('%s/', rtrim($currentFilterPath, '/')),
    sprintf('%s/', $newFilterPath),
    $currentUrl
);

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

Successfully merging this pull request may close these issues.

2 participants