forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.liquid
36 lines (32 loc) · 926 Bytes
/
script.liquid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{% 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 %}