Hi,
I make use of product tags and metafields within products at a product variant level.
I am trying to create a JSON output within ‘send email’ for a multiple line order where the products have many tags and specific product.variant metafields. I understand that JSON can be created in a roundabout way but this isn’t the problem.
Trigger is when an order is created (testing as a draft order)
Within the email are conditions in liquid and it isolates lines with a particular tags_item for one value I need to return and it will also look for a particular metafield_item value based on a namespace.
It partially works.
The test draft order I am using has 3 different order.lines/products.
2 of these draft order lines have the metafield in question and these output properly but the third item doesn’t have this metafield and I suspect is returning nil amounts which means it isn’t outputting at all.
I’d prefer it to still show in the JSON, even if the metafield outputs as zero. The added issue is that any condition I try to create to show the line without a metafield doesn’t show the metafield but also returns the line items that DO have metafields a second time, which I do not want.
{
“email”: {{draftOrder.email | json}},
“order”: {{draftOrder.name | json}},
“order_lines”: [
{% for lineItems_item in draftOrder.lineItems %}
{% for tags_item in lineItems_item.product.tags %}
{% for metafields_item in lineItems_item.variant.metafields %}
{% if tags_item contains ‘Filter=estimated-delivery’ and metafields_item.namespace == “pre_order”%}
{“sku”: {{lineItems_item.sku | json}},
“preorder”: {{metafields_item.value | split: “=” | last | json}},
“timescale”: {{tags_item | remove: “Filter=estimated-delivery/” | json}}
{% elsif metafields_item == nil %}
,“sku”: {{lineItems_item.sku | json}},
“preorder”: “0”,
“timescale”: {{tags_item | remove: “Filter=estimated-delivery/” | json}}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
}
]
}
}
edit I should add that I have tried multiple versions of this code within the body of the email to get this to work but I cannot get the line that has the tag but doesn’t have the metafield to show at all.