Auto-tag orders that contain bundles
Use this task to automatically detect and tag orders that contain a complete bundle of products. Configure this task with as many bundles as you like, specifying a tag to add and a list of required SKUs.
Try this taskWhen it runs
Occurs whenever an order is created
What you choose
Tags and required SKUs
Documentation
Use this task to automatically detect and tag orders that contain a complete bundle of products. Configure this task with as many bundles as you like, specifying a tag to add and a list of required SKUs.
Fill in "Tags and required SKUs" option with tags on the left, and a comma-delimited lists of SKUs on the right.
Task code and subscriptions
You can edit the Liquid code after installing this task. View on GitHub or ask a question in the Mechanic Slack community.
Subscriptions
shopify/orders/create
How task subscriptions work
Option types and flags
- Tags and required SKUs (keyval, required)
Task code
{% assign tags_to_save = order.tags %}
{% assign order_skus = order.line_items | map: "sku" | uniq %}
{% for pair in options.tags_and_required_skus__keyval_required %}
{% assign tag = pair[0] %}
{% assign required_skus = pair[1] | split: "," %}
{% assign matched_sku_count = 0 %}
{% for order_sku in order_skus %}
{% if required_skus contains order_sku %}
{% assign matched_sku_count = matched_sku_count | plus: 1 %}
{% endif %}
{% endfor %}
{% if event.preview or matched_sku_count == required_skus.size %}
{% assign tags_to_save = tags_to_save | add_tag: tag %}
{% endif %}
{% endfor %}
{% if event.preview or tags_to_save != order.tags %}
{
"action": {
"type": "shopify",
"options": [
"update",
[
"order",
{{ order.id | json }}
],
{
"tags": {{ tags_to_save | json }}
}
]
}
}
{% endif %}
Mechanic Liquid reference
Default option values
- Tags and required SKUs
{"Summer bundle" => "SUN01,SUN02,SUN03", "Winter bundle" => "SNOW01,SNOW02,SNOW03"}