Shopify / Shopify/liquid

filter_value.url_to_add it's not replacing the active filter

Open
#1,506 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

filter_value.url_to_add it's definitely not working as I'd expect from reading the doc:
https://shopify.dev/api/liquid/objects/filter-value#filter_value-url_to_add

When I use it's not returning me the current page URL with the filter value parameter added, it's instead returning me the current page url with an extra url parameter appended at the end. Which sounds similar, but it's all different story.

Let me explain better. Let's assume I have two sets of filters (color and size).

Colors:
<a href="/collections/sale?filter.v.option.color=black">Black</a>
<a href="/collections/sale?filter.v.option.color=red">Red</a>
<a href="/collections/sale?filter.v.option.color=blue">Blue</a>

Sizing:
<a href="/collections/sale?filter.v.option.size=M">M</a>
<a href="/collections/sale?filter.v.option.size=L">L</a>

All good so far. Let's say that I click on color Black, this is what happens:

Colors:
<a href="/collections/sale?filter.v.option.color=black">Black</a>
<a href="/collections/sale?filter.v.option.color=black&filter.v.option.color=red">Red</a>
<a href="/collections/sale?filter.v.option.color=black&filter.v.option.color=blue">Blue</a>

Sizing:
<a href="/collections/sale?filter.v.option.color=black&filter.v.option.size=M">M</a>
<a href="/collections/sale?filter.v.option.color=black&filter.v.option.size=L">L</a>

Sizing looks good to me, color nope. Now let's click on Blue, this is what happen:

Colors:
<a href="/collections/sale?filter.v.option.color=blue&filter.v.option.color=black">Black</a>
<a href="/collections/sale?filter.v.option.color=blue&filter.v.option.color=red">Red</a>
<a href="/collections/sale?filter.v.option.color=blue">Blue</a>

Sizing:
<a href="/collections/sale?filter.v.option.color=bluefilter.v.option.size=M">M</a>
<a href="/collections/sale?filter.v.option.color=bluefilter.v.option.size=L">L</a>

So if the filter is a different filter, the url looks good as expected, both sizing filters are perfect, but within the same filter is not assembling the url correctly. Bottom line I think that this is a bug. Is there a way that this can be used? Am I missing something?

Let me know if you have ideas.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the documented filter_value.url_to_add examples from the issue, especially switching between two values in the same filter and then between different filters. Compare the generated URLs with the expected replacement and preservation behavior shown in the examples; the issue is done when those URLs are assembled correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.