forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.liquid
41 lines (35 loc) · 1.42 KB
/
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
37
38
39
40
41
{% if event.preview %}
{% capture inventory_level_json %}
{
"inventory_item_id": 271878346596884015,
"location_id": 48752903,
"available": 5
}
{% endcapture %}
{% assign inventory_level = inventory_level_json | parse_json %}
{% endif %}
{% assign cache_key = "inventory_level:" | append: inventory_level.inventory_item_id | append: "/" | append: inventory_level.location_id %}
{% assign previous_available = cache[cache_key] %}
{% if previous_available != nil %}
{% assign available_difference = inventory_level.available | minus: previous_available %}
{% if available_difference >= 0 %}
{% assign available_difference = "+" | append: available_difference %}
{% endif %}
{% action "email" %}
{
"to": {{ options.email_recipient__email_required | json }},
"subject": {{ options.email_subject__required | replace: "AVAILABLE", inventory_level.available | replace: "DIFFERENCE", available_difference | strip | json }},
"body": {{ options.email_body__required_multiline | replace: "AVAILABLE", inventory_level.available | replace: "DIFFERENCE", available_difference | strip | newline_to_br | json }},
"reply_to": {{ shop.customer_email | json }},
"from_display_name": {{ shop.name | json }}
}
{% endaction %}
{% endif %}
{% action "cache" %}
{
"set": {
"key": {{ cache_key | json }},
"value": {{ inventory_level.available }}
}
}
{% endaction %}