Hi @malalta , we are trying to fix the Product Sorting on our store front end for our tag pages. We have setup our collection pages in such a way, on choosing any collection, by default ‘men’ product tag gets applied as a filter. Here’s the link to a collection page for better understanding.
The challenge we are facing is with our default product Sort. Currently on selecting any values in Sort, it sorts the products on the collection page rather than sorting it on the tag page and returns result with products sorted on collection page similar to link.
Please help us fix this issue with relevant solution as we are looking to sort the products on our tag pages for our collections.
When you’re on a collection page, including a collection filtered by a tag, you can sort the items on it via a “sort_by” query parameter in the URL. For example:
…so then, if I’m understanding what you’re after you could sort your “paint-splatter” collection, filtered by your “men” tag, and sorted by price low to high (“price-ascending”) with the following URL:
On your current store theme the sort dropdown is a
where each
tag contains a link with the appropriate sort_by query parameter included - however it uses your collection URL (first version at the top of this post) not a URL with the tag included (second version).
To change this, you’ll need to find the liquid template that has the sort widget in it. Try starting in “templates/collection.liquid” and follow it to the appropriate “sections/” or “snippets/” files.
As a guess based on your HTML, it’ll probably look something like this:
{% for option in collection.sort_options %}
- {{ option.name }}
{% endfor %}
You’ll want to include some liquid code that updates the URL to contain the tag(s) your current page is filtered by:
{%- capture tags_for_url -%}
{%- for tag in current_tags -%}
{{- tag -}}{%- unless forloop.last %}+{% endunless -%}
{%- endfor -%}
{%- endcapture -%}
{% for option in collection.sort_options %}
- {{ option.name }}
{% endfor %}
This is untested and could (probably!) include some typos, but it should be enough to get you started.