[RESOLVED] Display Collection on Product Page

Highlighted
Shopify Partner
695 0 15

Hi all,

I'm sure this is simples, in fact I had a previous theme that actually had this built in, but the current one doesn't...

On the product page, I want to add a bit of liquid that shows the custom collection that the product is part of, as a link. I will code this into the page via a snippet so that this is what happens:

"blah blah product description

This product is part of my {whatever custom} Collection"

Where the part in the brackets takes you straight to the collection page. I don't want it to display ALL collections it is part of, and as all the other collections it will be part of are smart collections, I'm sure that is reasonably simple to do?

I'm on Tonal Theme

Cheers

Rachel

 

 

jewellery designer-maker & nature inspired photographer | West Yorkshire, UK
0 Likes
Highlighted
Astronaut
1890 1 431

You can use product.collections to return an array of the collections that the product belongs to.  From there, you will probably just want to return the first collection in that array.

{% assign product_collection = product.collections.first %}
{% if product_collection %}
This product is part of my {{ product_collection.title | link_to: product_collection.url }} Collection
{% endif %}

I hope this helps.

0 Likes
Highlighted
Shopify Partner
695 0 15

Hi Alex, 

Cheers for the code, that's a great start, and works as such. However, it seems to return whatever the first collection it appears in - so for my new collection, Alchemy, everything is great as it's the only 'A' collection. For any other collection, it returns 'Best Sellers' as alphabetically that's the first collection other products are part of. It's also a smart collection. 

I'm thinking that because each item only lives in one custom collection, versus several smart collections, can I say 'please return the first custom collection this belongs to'. Is that possible?

Or, should I tag my custom collections, and change that code to say 'please return the first collection with tag xxx this belongs to' - would that be easier from a liquid point of view?

 

 

jewellery designer-maker & nature inspired photographer | West Yorkshire, UK
0 Likes
Highlighted
Shopify Partner
695 0 15

any ideas, guys? 

thanks :)

jewellery designer-maker & nature inspired photographer | West Yorkshire, UK
0 Likes
Highlighted
Astronaut
1890 1 431

How do you define which collection is considered a custom collection?  Or, conversely, how do you define which collection is considereed not a custom collection?

For example, is it easier to list all of your custom collections?  Or is it easier to list all of your non-custom collections and assume that all other collections are custom collections?

0 Likes
Highlighted
Shopify Partner
695 0 15

I'm not sure - but I do know for sure that:
a) I don't know how to do either

b) I only want their single custom collection to show, rather than the several smart collections that they also live in.

I'm sure there are several ways of making it happen?

Does that help at all?!!

jewellery designer-maker & nature inspired photographer | West Yorkshire, UK
0 Likes
Highlighted
Astronaut
1890 1 431

In your shop, under the "Shop" menu, there are a total of 7 columns: Jewellery, Collections, Prices, Other, Art House Products, Art House Designs and Art House Prices.  I believe you created a navigation linklist for each of these columns.  Is that right?

Would the following example work out for you?

All items in the "Jewellery", "Collections", "Art House Products" and "Art House Designs" columns/linklists are custom collections (as opposed to smart collections).  In other words, one of these items is the collection that you want to have displayed on the product page.

0 Likes
Highlighted
Shopify Partner
695 0 15

It's only the custom collections that feature in the 'Collections' linklist that I want to pull through for each product. Is there any way, in liquid, that I can say 'display whichever collection this product is from, from within this specific linklist' ?

Do you know how I would define that, codewise?

I appreciate your help :)

jewellery designer-maker & nature inspired photographer | West Yorkshire, UK
0 Likes
Highlighted
Astronaut
1890 1 431

Try the following code.  Change the first line to include the handle of your "Collections" linklist.

{% assign custom_collection_linklist = 'all-collections' %}

{% assign product_collections = product.collections | map:'handle' %}
{% for link in linklists[custom_collection_linklist].links %}
  {% if link.type == 'collection_link' and product_collections contains link.object.handle %}
    {% assign product_collection = link.object %}
    {% break %}
  {% endif %}
{% endfor %}

{% if product_collection %}
  This product is part of my {{ product_collection.title | link_to: product_collection.url }} Collection
{% endif %}

I hope this helps.

0 Likes
Highlighted
Shopify Partner
695 0 15

Alex, that is fantastic, it works perfectly. Thanks so much for all your help! :)
(changing title to reflect this)

jewellery designer-maker & nature inspired photographer | West Yorkshire, UK
0 Likes