Hi there,
Just wondering if someone could help me fix the last bit of my code so I can make the swatches etc work for my new set of variables on a particular product.
Image is currently what I’m dealing with, original product variables are showing in the usual spot as swatches and there is two drop-downs located at the bottom of the description with all the merged variants from 2 products.
Needing to obviously usher my code a bit to locate the default option selectors? I’m not that code savy bu I experiment and sometimes get great results.
Can anyone offer some advice?
Thanks in advance.
Cam.
Image:
Code:
{% comment %}
========================================
Code by Jason [email removed] Freakdesign
Relates to a blog post:
https://freakdesign.myshopify.com/admin/blogs/4018421/articles/105830151
{% endcomment %}
{% section ‘product-template-5000’ %}
{% comment %}
Add in all the variants from the current product.
{% endcomment %}
{% assign productVariants = product.variants %}
{% comment %}
Grab the option names of the current product
{% endcomment %}
{% assign productOptionNames = product.options | json %}
{% comment %}
First add all the handles of the other products that need to be bundled in.
The strip is just added for safety, in case you add a space after that comma in error.
Notice that there is no check to see if the options match. You should do that…
{% endcomment %}
{% assign productList = ‘5000-gildan-t-shirts-1,5000-gildan-t-shirts-2’ | replace:’ ’ | split:‘,’ %}
{% for productListHandle in productList %}
{% comment %}
Grab a product
{% endcomment %}
{% assign productListItem = all_products[productListHandle] %}
{% comment %}
Grab the option names of the additional product
{% endcomment %}
{% assign productListOption = productListItem.options | json %}
{% comment %}
Do nothing more if the option names don’t match
{% endcomment %}
{% unless productListOption == productOptionNames %}{% continue %}{% endunless %}
{% comment %}
Update our master variant list with the additional variants
{% endcomment %}
{% assign productVariants = productVariants | concat:productListItem.variants %}
{% endfor %}
{% comment %}
We should now have a pretty big list of variants so let’s push all of them out into a standard