Hi,
I’d like to update my theme code to make a rule where … if there’s only one product in a collection, on the catalog page, the href goes directly to the single product (instead of the “entire” collection). Can anyone help me?
Thanks,
Steve
Hi,
I’d like to update my theme code to make a rule where … if there’s only one product in a collection, on the catalog page, the href goes directly to the single product (instead of the “entire” collection). Can anyone help me?
Thanks,
Steve
Hi,
Could you provide a screenshot of your collections page liquid?
So I could see a bit how it’s structured in your Shop and provide a solution!
Thanks for your offer to help!
Each of these collections on the “Catalog” page currently contain only one product. I’d like to have images on the “Catalog” page link directly to the single product affiliated with the collection. Effectively, I’m trying to go from image one to image three in the below images.
Thanks again.
My pleasure!
Thank you for the explanation!
In order for me to propose a code solution, I would need the collection.liquid file in your theme code.
You can access it by going to Actions > Edit Code
Then in templates you should find something like page.list-collections.liquid.
Inside that page there will most likely be a section rendered. If it’s the case go to the written section and screenshot that code for me.
Thank you
Hi!
I’ve taken the time to code you a solution
You can save a copy of your actual code just to be safe before doing the next step…
Replace the code in your collection-grid-item.liquid file with this code :
{% comment %}
This snippet is used to showcase each collection during the loop,
'for product in collections[collection_handle].products' in list-collections.liquid.
{% endcomment %}
{% comment %}
Set the default grid_item_width if no variable is set
{% endcomment %}
{% unless grid_item_width %}
{% assign grid_item_width = 'medium--one-half large--one-third' %}
{% endunless %}
{% comment %}
Set the default image_size if no variable is set
{% endcomment %}
{% unless image_size %}
{% assign image_size = 'grande' %}
{% endunless %}
{% assign no_collection_image = true %}
{% if collections[collection_handle].products.size == 1 %}
{% else %}
{% endif %}
{% comment %}
Use capture to put the collection title in a variable that is used in liquid filters
{% endcomment %}
{% if collection == blank %}
{% assign collection_title = 'home_page.onboarding.collection_title' | t %}
{% else %}
{% assign collection_title = collections[collection_handle].title | escape %}
{% endif %}
{% if collection.image %}
{%- assign collection_image = collection.image -%}
{% elsif collection.products.first and collection.products.first.featured_media != empty %}
{%- assign collection_image = collection.products.first.featured_media.preview_image -%}
{% else %}
{%- assign collection_image = blank -%}
{% endif %}
{% if grid_item_responsive %}
{% if collection == blank %}
{{ 'collection-1' | placeholder_svg_tag: 'placeholder-svg' }}
{% else %}
{% endif %}
{% else %}
{% if collection == blank %}
{% capture current %}{% cycle 1, 2, 3, 4, 5, 6 %}{% endcapture %}
{{ 'collection-' | append: current | placeholder_svg_tag: 'placeholder-svg' }}
{% else %}
{% endif %}
{% endif %}
{{ collection_title }}
{% if collections[collection_handle].products.size == 1 %}
{% else %}
{% endif %}
The magic happens here:
{% if collections[collection_handle].products.size == 1 %}
{% else %}
{% endif %}
I’ve added an if statement {% if collections[collection_handle].products.size == 1 %} checking the size of the collection and changed the href from the tag to the one you can see in the code above.
Hope this helps!
It should fix your problem right away I’ve tested it!
Works brilliantly! Thanks so much for your help; it’s very much appreciated.