Conversion: Resource lookups in task option fields
An oft utilized feature of Mechanic is the ability to add Liquid tags into task options fields, such as a configurable email body. Additionally, these Liquid tags (currently) support inline resource lookups for data not available in the event webhook. However, for products and variants this no longer works as of the Feb 1, 2025 REST deprecation.
{%- assign qualifying_product = nil -%}
{%- for line_item in order.line_items -%}
{%- if line_item.product.product_type == "Special" -%}
{% assign qualifying_product = line_item.product -%}
{%- break -%}
{%- endif -%}
{%- endfor -%}
{%- if qualifying_product != blank -%}
Special product notice for {{ qualifying_product.title }}...
{%- endif -%}The code above could be utilized directly in a multiline task option field, and it would output a string of text (e.g. "Special product notice for Widget - Red...") into the assigned option field variable.
One method of conversion for lookup fields is to utilize a GraphQL query directly in the option field, which naturally has some caveats.
{%- assign order_id = order.admin_graphql_api_id | default: "gid://shopify/Order/12345" -%}
{%- capture query -%}
query {
order(id: {{ order_id | json }}) {
id
lineItems(first: 250) {
nodes {
id
product {
title
productType
}
}
}
}
}
{%- endcapture -%}
{%- assign result = query | shopify -%}
{%- assign qualifying_product = nil -%}
{%- for line_item in result.data.order.lineItems.nodes -%}
{%- if line_item.product.productType == "Special" -%}
{% assign qualifying_product = line_item.product -%}
{%- break -%}
{%- endif -%}
{%- endfor -%}
{%- if qualifying_product != blank -%}
Special product notice for {{ qualifying_product.title }}...
{%- endif -%}It can be helpful when using a GraphQL query in a task option field to add the code flag to the option field, which will add line numbers and give access to Mechanic code snippets.


Last updated
Was this helpful?