{% comment %} Renders product variant-picker Accepts: - product: {Object} product object. - block: {Object} passing the block information. - product_form_id: {String} Id of the product form to which the variant picker is associated. - update_url: {Boolean} whether or not to update url when changing variants. If false, the url isn't updated. Default: true (optional). Usage: {% render 'product-variant-picker', product: product, block: block, product_form_id: product_form_id %} {% endcomment %} {%- assign items_in_cart = cart.items | map: 'id' -%} {%- assign unique_items_in_cart = items_in_cart | join: ',' | uniq -%} {% for item in cart.items %} {% endfor %} {%- unless product.has_only_default_variant -%} {%- if block.settings.picker_type == 'button' -%} {%- comment %} Find the selected collection that matches the product title. {%- endcomment %} {% for collection in collections %} {% assign collection_title_lower = collection.title | downcase %} {% assign product_title_lower = product.title | downcase %} {% if product_title_lower contains collection_title_lower %} {% assign selected_collection = collection %} {% break %} {% endif %} {% endfor %} {% if selected_collection %} {% assign metal_set = '' | split: ',' %} {% assign karat_set = '' | split: ',' %} {% assign metal_color_set = '' | split: ',' %} {% assign length_set = '' | split: ',' %} {% assign width_set = '' | split: ',' %} {% assign type_set = '' | split: ',' %} {% assign bracelet_length_set = '' | split: ',' %} {% assign necklace_length_set = '' | split: ',' %} {% assign anklet_length_set = '' | split: ',' %} {%- assign metal_color_images_array = '' -%} {%- assign metal_colors_processed = '' | split: ',' -%} {% for product2 in selected_collection.products %} {% for variant in product2.variants %} {% assign metal_option = variant.option3 %} {% if metal_option != '' %} {% assign karat = metal_option | remove: 'YG' | remove: 'RG' | remove: 'WG' %} {% if metal_option == '10K' or metal_option == '14K' or metal_option == '18K' or metal_option == '21K' or metal_option == '22K' %} {% assign metal_option = metal_option | append: 'YG' %} {% assign metal_color = 'YG' %} {% else %} {% assign metal_color = metal_option | remove: karat %} {% endif %} {% unless metal_colors_processed contains metal_color %} {% if variant.featured_image %} {% assign image_url = variant.featured_image.src | json %} {% assign metal_color_images_array = metal_color_images_array | append: '{"metal_color":"' | append: metal_color | append: '", "image_url":' | append: image_url | append: '},' %} {% assign metal_colors_processed = metal_colors_processed | append: metal_color %} {% endif %} {% endunless %} {% endif %} {% endfor %} {% endfor %} {%- comment %} Collect unique metals, lengths, widths, types, karats, and metal colors from the variants. {%- endcomment %} {% for product2 in selected_collection.products %} {% assign product_type = product2.metafields.custom.type.value %} {%- for variant in product2.variants %} {% assign metal_option = variant.option3 %} {% if metal_option != '' %} {% comment %} Extract karat and metal color {% endcomment %} {% assign karat = metal_option | remove: 'YG' | remove: 'RG' | remove: 'WG' %} {% if metal_option == '10K' or metal_option == '14K' or metal_option == '18K' or metal_option == '21K' or metal_option == '22K' %} {% assign metal_option = metal_option | append: 'YG' %} {% assign metal_color = 'YG' %} {% else %} {% assign metal_color = metal_option | remove: karat %} {% endif %} {% assign karat_set = karat_set | join: ',' | append: ',' | append: karat | split: ',' | uniq | sort %} {% assign metal_color_set = metal_color_set | join: ',' | append: ',' | append: metal_color | split: ',' | uniq | sort %} {% assign metal_set = metal_set | join: ',' | append: ',' | append: metal_option | split: ',' | uniq | sort %} {% endif %} {% assign length_option = variant.option1 %} {% if length_option != '' %} {% if product_type == 'Bracelet' %} {% assign bracelet_length_set = bracelet_length_set | join: ',' | append: ',' | append: length_option | split: ',' | uniq | sort %} {% elsif product_type == 'Anklet' %} {% assign anklet_length_set = anklet_length_set | join: ',' | append: ',' | append: length_option | split: ',' | uniq | sort %} {% elsif product_type == 'Necklace' %} {% assign necklace_length_set = necklace_length_set | join: ',' | append: ',' | append: length_option | split: ',' | uniq | sort %} {% endif %} {% endif %} {% assign width_option = variant.option2 %} {% if width_option != '' %} {% assign width_set = width_set | join: ',' | append: ',' | append: width_option | split: ',' | uniq %} {% endif %} {% endfor %} {% endfor %} {%- comment %} Build the variants map, including 'type' in the key. {%- endcomment %} {% assign variants_array = "" %} {% for product2 in selected_collection.products %} {% assign product_type = product2.metafields.custom.type.value %} {% for variant in product2.variants %} {% assign length_option = variant.option1 %} {% assign width_option = variant.option2 %} {% assign metal_option = variant.option3 %} {% if metal_option != '' %} {% assign karat = metal_option | remove: 'YG' | remove: 'RG' | remove: 'WG' %} {% if metal_option == '10K' or metal_option == '14K' or metal_option == '18K' or metal_option == '21K' or metal_option == '22K' %} {% assign metal_color = "YG" %} {% else %} {% assign metal_color = metal_option | remove: karat %} {% endif %} {% endif %} {% assign key = length_option | append: "_" | append: width_option | append: "_" | append: karat | append: "_" | append: metal_color %} {% capture value %} { "id": {{ variant.id }}, "length": "{{ length_option }}", "width": "{{ width_option }}", "karat": "{{ karat }}", "metal_color": "{{ metal_color }}", "type": "{{ product_type }}", "weight": "{{ variant.metafields.custom.weight }}" } {% endcapture %} {% assign variant_json = '{ "key": "' | append: key | append: '", "value": ' | append: value | append: ' }' %} {% assign variants_array = variants_array | append: variant_json | append: "," %} {% endfor %} {% endfor %} {% assign variants_json = "[" | append: variants_array | append: "]" %} {%- comment %} Initialize the variantsMap JavaScript object. {%- endcomment %} {%- comment %} Generate the karat option buttons. {%- endcomment %}
{% for karat_option in karat_set %} {% if karat_option != '' %}
{% endif %} {% endfor %}
{%- comment %} Generate the metal color option buttons. {%- endcomment %} {%- assign metal_color_order = 'YG,RG,WG' | split: ',' -%}
{% for metal_color_option in metal_color_order %}
{% endfor %}
{%- comment %} Generate separate tables for each type (Bracelet, Anklet, Necklace) and for each combination of karat and metal color. {%- endcomment %} {% assign types = 'Bracelet' %} {% assign types2 = 'Anklet,Necklace' | split: ',' %} {% for karat_option in karat_set %} {% if karat_option == '' %} {% continue %} {% endif %} {% for metal_color_option in metal_color_set %} {% if metal_color_option == '' %} {% continue %} {% endif %} {% assign metal_key = karat_option | append: metal_color_option %} {% for metal in metal_set %} {% if metal == '' %} {% continue %} {% endif %} {% if metal contains karat_option and metal contains metal_color_option %} {%- comment %} MOBILE VERSION {%- endcomment %} {%- assign is_mobile = true -%} {% if is_mobile %} {% for type in types %} {% assign length_set_for_type = '' %} {% if type == 'Bracelet' %} {% assign length_set_for_type = bracelet_length_set %} {% endif %} {% if length_set_for_type != blank %} {% endif %} {% endfor %}
{% for type in types2 %} {% assign length_set_for_type = '' %} {% if type == 'Anklet' %} {% assign length_set_for_type = anklet_length_set %} {% elsif type == 'Necklace' %} {% assign length_set_for_type = necklace_length_set %} {% endif %} {% if length_set_for_type != blank %} {% endif %} {% endfor %}
{% endif %} {%- comment %} DESKTOP VERSION {%- endcomment %} {%- assign is_mobile = false -%} {% unless is_mobile %} {% endunless %} {% endif %} {% endfor %} {% endfor %} {% endfor %} {%- comment %} Total weight displays for each karat and metal color combination. {%- endcomment %}
{% for karat_option in karat_set %} {% if karat_option != '' %}
{{ karat_option }} {% assign ordered_metal_colors = 'YG,RG,WG' | split: ',' %} {% for metal_color_option in ordered_metal_colors %} {% if metal_color_set contains metal_color_option %} {% assign metal_key = karat_option | append: metal_color_option %}
{{ metal_color_option | remove: karat_option }}: 0 g
{% endif %} {% endfor %}
{% else %} {% continue %} {% endif %} {% endfor %}
ADD TO CART
{%- comment %} JavaScript code to handle the tables and interactions. {%- endcomment %} {%- comment %} Style adjustments (hide all tables by default). {%- endcomment %} {% else %}

NO COLLECTION FOUND!

{% endif %}
{%- else -%} {%- endif -%} {%- endunless -%}