Draft Orders - Fractional

{% if form.method == "POST" %} {% assign total_values = form.params.metafield-namespaces.size %} {% assign total_values = total_values - 1 %} {% if "Variant" == "Product" %} {% assign updated_product = "Product" | new: api_product.id %} {% else %} {% assign updated_product = "Product::Variant" | new: api_variant.id %} {% endif %} {% assign updated_product.metafields = [] %} {% if total_values >= 0 %} {% for i in (0..total_values) %} {% if form.params.metafield-keys[i] && form.params.metafield-namespaces[i] && form.params.metafield-values[i] %} {% assign meta = "Metafield" | new %} {% assign meta.value_type = 'string' %} {% assign meta.key = form.params.metafield-keys[i] %} {% assign meta.namespace = form.params.metafield-namespaces[i] %} {% assign meta.value = form.params.metafield-values[i] %} {% if "Variant" == "Product" %} {% for n in api_product.metafields %} {% if n.namespace == form.params.metafield-namespaces[i] and n.key == form.params.metafield-keys[i] %} {% assign meta.id = n.id %} {% endif %} {% endfor %} {% assign updated_product.metafields[updated_product.metafields.size] = meta %} {% else %} {% for n in api_variant.metafields %} {% if n.namespace == form.params.metafield-namespaces[i] and n.key == form.params.metafield-keys[i] %} {% assign meta.id = n.id %} {% endif %} {% endfor %} {% assign updated_product.metafields[updated_product.metafields.size] = meta %} {% endif %} {% endif %} {% endfor %} {% endif %} {% if "Variant" == "Product" %} {% assign api_product = updated_product | update %} {% assign product = api_product | to_shopify %} {% else %} {% assign api_variant = updated_product | update %} {% assign variant = api_variant | to_shopify %} {% endif %} {% assign success = "You have successfully modified this item's metafields." %} {% endif %} {% include 'css-wizard' %} {% comment %} The files in the 'include' tags can be accessed by going to Templates > Snippets. {% endcomment %}

Metafield Editor

{{ api_product.title }}{% if "Variant" == "Variant" %} - {{ api_variant.title }}{% endif %}

{% if success %}
{{ success }}
{% endif %} {% assign meta_hash = {} %} {% if "Variant" == "Product" %} {% for m in api_product.metafields %} {% assign meta_hash[m.namespace][m.key] = m.value %} {% endfor %} {% else %} {% for m in api_variant.metafields %} {% assign meta_hash[m.namespace][m.key] = m.value %} {% endfor %} {% endif %}

Namespace: 1/4, Key: usd_, Current Value: {{ meta_hash["1/4"]["usd_"] }}

Namespace: 1/2, Key: usd_, Current Value: {{ meta_hash["1/2"]["usd_"] }}