(SOLVED)how to build custom collection - specific variants with links directly to that variant

Highlighted
Shopify Partner
200 0 23

No problem! although you shouldnt be thanking me until we get you a solution =P.

Ok so thinking though the logic on this one.

  1. Shopify puts products into a collection based on the variant title
  2. your code outputs each product in that collection linking to the product in general. Note: even though the collection has sorted the products, all the products still have multiple variants. 
  3. Problem- How is the code suppose to know which variant you want selected?
  4. Next step would be to somehow create a relationship between the collection and which variant you want selected.
  5. One option could be using the title of the collection. somthing like...
{% for variant_link in product.variants %}
  {% if collection.title contains variant_link %}
    {% assign product_link = variant_link.url %}
    {% endif %}
{% endfor %}
  1. then from there you would need to replace all references to "{{product.url}}" with "{{product_link}}".

This is the logic. But be warned it could break your other collections. You would be smart to create new collection template. Im sorry to be so short, im suppose to be eating dinner with my girlfriend and she is about to kick my a**!!

If you are not a very experianced coder I would wait for futher assistance from someone who is! I would hate to be responable for breaking your theme ;)

1 Like
Highlighted
Tourist
31 0 1

Awesome

 

Will test this out when I get to the office tomorrow and update back

Ive already made a duplicate of the gridview and the collection.liquid to use for these specific collections and applied it as template. 

I can only break those specific currently unused collections at least!

 

Dont let your girlfriend get too mad! haha ty again for your help

0 Likes
Highlighted
Shopify Partner
200 0 23

Ok Update! I have this chunk of code that will show how the process works!

{% for variant_link in product.variants %}
  
  Variant Url: {{variant_link.url}} <br> 
  Collection Name: {{collection.title}} <br>
  Variant Title:{{ variant_link.title}} <br>
  	{% if variant_link.title contains collection.title %}
  		MATCH <!-- If the variant title has your collection name in it echo MATCH and asign the url  -->
  		{% assign product_link = variant_link.url %}
  		{{product_link}}
  	{%endif%}
	<hr>
  {% endfor %}

If you place this right after your Product loop

{% for product in collection.products %}{% if product.type == 'Product Fee' %}{% continue %}{% endif %}....

It will list out what is happening. Below is clean code suitable for a live site. 

  {% for variant_link in product.variants %}
  	{% if variant_link.title contains collection.title %}
  		{% assign product_link = variant_link.url %}
        {% break %}{%comment%}This brake stops the loop, making the url the FIRST variant that matches{%endcomment%}
  	{%endif%}
  {% endfor %}

From there you would use {{product_link}} anywhere you want. in your example above you would change..

<a href="{{ product.url }}" class="grid-link">

<!-- TO THIS -->

<a href="{{ product_link }}" class="grid-link">

Keep in mind, the title of the collection MUST be matchable to the variand name. ie...
135r/55/65 != 135r5565.

Let me know if this all makes sense!

1 Like
Highlighted
Tourist
31 0 1

hey

 

that makes perfect sense to me. going to be working on it here shortly just got to the office. will post back after!

thanks again for all your help!

 

matt

0 Likes
Highlighted
Tourist
31 0 1

Hey

Okay that worked

https://gogotires.com/collections/215-60r16

the products are linking directly to the specific variant for the customer. :)

 

Now I do have a further question/concern, how do I make the collection show the specific variant price/instock  . 

So right now, the tires listed on that page show the lowest variant price, and as long as any variant has stock it shows as INSTOCK as opposed to  "please contact us for inquiries"

 

This is all on the collection page, the product page works perfectly.

Thanks again you are the best to even get me this far

if you got any ideas on these other ones let me know, im looking at the code now for it

 

matt

0 Likes
Highlighted
Tourist
31 0 1

also , you know how there was a variable called variant_link

 

is there a listing of other variant variables i can access? I am trying to find it online for one for price and stock levels as I imagine I could do it a similar way to the variant link

0 Likes
Highlighted
Shopify Partner
200 0 23

Hmm give this a try! First update this code with the "wanted_var_price"

{% for variant_link in product.variants %}
  	{% if variant_link.title contains collection.title %}
  		{% assign product_link = variant_link.url %}
        {% assign wanted_var_price = variant_link.price %}
        {% break %}{%comment%}This brake stops the loop, making the url the FIRST variant that matches{%endcomment%}
  	{%endif%}
  {% endfor %}

Then find this snippet of code 

 {% capture price %}<strong>{{price}}</strong>{% endcapture %}

Change to

 {% capture price %}<strong>{{ wanted_var_price | money }}</strong>{% endcapture %}

And that should work! As for your second question, there are plenty more variable object. Here is a great reference. One thing to keep in mind though, the "variant_link" was kind of a custom one we created.

1 Like
Highlighted
Tourist
31 0 1

that worked great, you are really good at this. I was close to getting it on my own but had a couple syntax issues compared to your code.

 

Now im just working on the stock levels / greying out an item if that specific variant does not have stock. Will update back here if I cant get it done but I think you gave me a great starting point to work from.

that reference page is amazing. i wish i could have found it WAY SOONER.

 

thanks!

 

matt

 

0 Likes
Highlighted
Shopify Partner
200 0 23

No problem! Im glad we got it worked out! Report back later, I would love to see the site once you get further along!

 

0 Likes
Highlighted
Tourist
31 0 1

will do forsure, I just took a look at your website, looks awesome

 

It will be a long process to create what I want to create, these collections are just what I need as the end result.

0 Likes