How can I correctly update an order metafield in liquid code?

rdaniel
Tourist
11 0 3

Hey,

 

I'm not quite getting the syntax required inside update order metafield. I thought I could write normal liquid code, but it seems that I can't? Is that correct? Or am I just missing something?

 

 

{% assign am_stock = false %}
{% assign am_special_request = false %}
{% assign am_pre_order = false %}
{% assign am_back_order = false %}
{% assign cm_dropshipping = false %}
{% assign cm_resell = false %}
{% assign s_gardners = false %}
{% assign s_forlagssentralen = false %}
{% for lineItems_item in order.lineItems %}
    {% for metafields_item in lineItems_item.variant.metafields %}
        {% if metafields_item.namespace == "item" %}
            {% if metafields_item.key == "acquisition-method" %}
                {% for am in metafields_item.value %}
                    {% if am.title.value == "Stock" %}
                        {% assign am_stock = true %}
                    {% elsif am.title.value == "Special request" %}
                        {% assign am_special_request = true %}
                    {% elsif am.title.value == "Pre-order" %}
                        {% assign am_pre_order = true %}
                    {% elsif am.title.value == "Back-order" %}
                        {% assign am_back_order = true %}
                    {% endif %}
                {% endfor %}
            {% endif %}
            {% if metafields_item.key == "completion-method" %}
                {% for cm in metafields_item.value %}
                    {% if cm.title.value == "Dropshipping" %}
                        {% assign cm_dropshipping = true %}
                    {% elsif cm.title.value == "Resell" %}
                        {% assign cm_resell = true %}
                    {% endif %}
                {% endfor %}
            {% endif %}
            {% if metafields_item.key == "supplier" %}
                {% for s in metafields_item.value %}
                    {% if s.title.value == "Gardners" %}
                        {% assign s_gardners = true %}
                    {% elsif s.title.value == "Forlagssentralen" %}
                        {% assign s_forlagssentralen = true %}
                    {% endif %}
                {% endfor %}
            {% endif %}
        {% endif %}
    {% endfor %}
{% endfor %}
{% if order.lineItems > 1 %}
    {% if cm_dropshipping and cm_resell %}
        "TRUE"
    {% elsif cm_dropshipping and cm_resell != true %}
        {% if s_gardners and s_forlagssentralen %}
            "TRUE"
        {% else %}
            "FALSE"
        {% endif %}
    {% elsif am_stock and am_pre_order %}
        "TRUE"
    {% elsif am_stock and am_back_order %}
        "TRUE"
    {% elsif am_special_request and am_pre_order %}
        "TRUE"
    {% elsif am_special_request and am_back_order %}
        "TRUE"
    {% else %}
        "FALSE"
    {% endif %}
{% else %}
    FALSE
{% endif %}

 

 

I'm trying to update a metafield to set to true if the delivery will be split and false if it won't. But I'm getting this error when I try to write this inside value:

 

Correct this workflow issue:
An internal error occured. Try again later.
Replies 2 (2)

DaveMcV
Shopify Staff
95 28 25

Hi Rdaniel,

 

It looks like there is a problem with this snippet:

{% for cm in metafields_item.value %}
                    {% if cm.title.value == "Dropshipping" %}
                        {% assign cm_dropshipping = true %}
                    {% elsif cm.title.value == "Resell" %}
                        {% assign cm_resell = true %}
                    {% endif %}
                {% endfor %}

 

Specifically, the `metafields_item.value` field is unknown to the Liquid compiler at compile time, so it cannot be iterated over. I believe it will interpret it as a `string`.

 

Hopefully that helps you debug further!

DaveMcV | Flow Development Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
rdaniel
Tourist
11 0 3

Ok. I forgot to mention that the metafields_item is a metaobject reference... So will it still be interpret as ´string´?