{% layout none %}
{% assign all_text = '' %}
{% unless product.has_only_default_variant %}
{% for option in product.options_with_values %}
{% if settings.variant_type == 'button' %}
{%- assign swatch_file_extension = 'png' -%}
{%- assign is_color = false -%}
{%- assign color_swatch_drop = option -%}
{%- assign color_option_index = 0 -%}
{%- if settings.product_color_swatches -%}
{%- for option in product.options_with_values -%}
{%- if option == color_swatch_drop -%}
{%- assign color_option_index = forloop.index0 -%}
{%- assign downcased_option = color_swatch_drop.name | downcase -%}
{%- if downcased_option contains 'color' or downcased_option contains 'colour' -%}
{%- assign is_color = true -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- assign other_colors = '' -%}
{%- if product.metafields.related.colors -%}
{%- for other_product in product.metafields.related.colors.value -%}
{%- for other_option in other_product.options_with_values -%}
{%- assign other_option_name = other_option.name | handleize -%}
{% assign variant_option = '' %}
{% for variant in other_product.variants %}
{%- capture variant_option -%}{{ variant_option }}{% if variant_option != blank %},{% endif %}{""option_2"":""{{ variant.option2 }}"",""available"":""{{ variant.available }}"",""price"":""{{ variant.price }}"",""sku"":""{{ other_product.id | append: '_' | append:variant.id }}""}{% endcapture %}
{% endfor %}
{%- if other_option_name == 'color' or other_option_name == 'colour' -%}
{%- assign other_option_value = other_option.values[0] -%}
{%- assign color_image = other_option_value | handle | append: '.' | append: swatch_file_extension | asset_img_url: '50x' | prepend: 'https:' | split: '?' | first -%}
{%- assign color_swatch_fallback = other_option_value | split: ' ' | last | handle -%}
{% assign f_image = other_product.featured_image | img_url: 'master' | prepend: 'https:' %}
{% assign secondary_image = other_product.images[1] | img_url: 'master' | prepend: 'https:' %}
{%- capture other_colors -%}{{ other_colors }}{% if other_colors != blank %},{% endif %}{""featured_image"":""{{ f_image }}"",""secondary_image"":""{{ secondary_image }}"",""color_image"":""{{ color_image }}"",""color_swatch_fallback"":""{{ color_swatch_fallback }}"",""product_handle"":""{{ other_product.url }}"",""product_title"":""{{ other_product.title }}"",""variant_option"":[{{ variant_option }}]}{%- endcapture -%}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
{%- endif -%}
{%- assign option_index = forloop.index -%}
{%- assign option_accesor = 'option' | append: option_index -%}
{%- assign optionHandle = option.name | handle -%}
{%- for value in option.values -%}
{%- if is_color -%}
{% assign variant_option = '' %}
{% for variant in product.variants %}
{%- capture variant_option -%}{{ variant_option }}{% if variant_option != blank %},{% endif %}{""option_2"":""{{ variant.option2 }}"",""available"":""{{ variant.available }}"",""price"":""{{ variant.price }}"",""sku"":""{{ product.id | append: '_' | append:variant.id }}""}{% endcapture %}
{% endfor %}
{%- assign color_image = value | handle | append: '.' | append: swatch_file_extension | asset_img_url: '50x' | prepend: 'https:' | split: '?' | first -%}
{%- assign color_swatch_fallback = value | split: ' ' | last | handle -%}
{% assign f_image = product.featured_image | img_url: 'master' | prepend: 'https:' %}
{% assign secondary_image = product.images[1] | img_url: 'master' | prepend: 'https:' %}
{%- capture other_colors -%}{""featured_image"":""{{ f_image }}"",""color_image"":""{{ color_image }}"",""secondary_image"":""{{ secondary_image }}"",""color_swatch_fallback"":""{{ color_swatch_fallback }}"",""product_handle"":""{{ product.url }}"",""product_title"":""{{ product.title }}"",""variant_option"":[{{ variant_option }}]}{% if other_colors != blank %},{% endif %}{{ other_colors }}{%- endcapture -%}
{% assign all_text = other_colors %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endunless %}
{""product_master_handle"": [{{ all_text }}]}"