forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset-inventory-levels-daily.json
21 lines (21 loc) · 3.13 KB
/
reset-inventory-levels-daily.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"docs": "Use this task to bring all of your inventory levels to the same place, every night.\n\nThis task resets your inventory levels every night, for a given collection ID.",
"halt_action_run_sequence_on_error": false,
"name": "Reset inventory levels daily",
"online_store_javascript": null,
"options": {
"inventory_level_to_apply__number_required": null,
"collection_id__number_required": null
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% if event.preview %}\n {\n \"action\": {\n \"type\": \"shopify\",\n \"options\": [\n \"post\",\n \"/admin/inventory_levels/set.json\",\n {\n \"inventory_item_id\": 1234567890,\n \"location_id\": {{ shop.primary_location_id | json }},\n \"available\": {{ options.inventory_level_to_apply__number_required | round | json }}\n }\n ]\n }\n }\n{% else %}\n {% assign collection_id = options.collection_id__number_required | round %}\n {% assign collection = shop.collections[collection_id] %}\n\n {% unless collection %}\n {% capture message %}No collection found with ID #{{ collection_id | json }}.{% endcapture %}\n {\"log\": {{ message | json }}}\n {% endunless %}\n\n {% if collection.products.count == 0 %}\n {% capture message %}No products in collection #{{ collection_id | json }}.{% endcapture %}\n {\"log\": {{ message | json }}}\n {% endif %}\n\n {% for product in collection.products %}\n {% for variant in product.variants %}\n {% if variant.inventory_management != \"shopify\" %}\n {% capture message %}Inventory management policy is {{ variant.inventory_management | json }}, skipping inventory update for {{ variant.title }} on {{ product.title }}{% endcapture %}\n {\"log\": {{ message | json }}}\n {% continue %}\n {% endif %}\n\n {% for inventory_level in variant.inventory_levels %}\n {% if inventory_level.location_id != shop.primary_location_id %}\n {% continue %}\n {% endif %}\n\n {% if inventory_level.available == options.inventory_level_to_apply__number_required %}\n {% capture message %}Inventory level is already {{ inventory_level.available | json }}, skipping inventory update for {{ variant.title }} on {{ product.title }}{% endcapture %}\n {\"log\": {{ message | json }}}\n {% continue %}\n {% endif %}\n\n {\n \"action\": {\n \"type\": \"shopify\",\n \"options\": [\n \"post\",\n \"/admin/inventory_levels/set.json\",\n {\n \"inventory_item_id\": {{ inventory_level.inventory_item_id | json }},\n \"location_id\": {{ inventory_level.location_id | json }},\n \"available\": {{ options.inventory_level_to_apply__number_required | round | json }}\n }\n ]\n }\n }\n {% endfor %}\n {% endfor %}\n {% endfor %}\n{% endif %}\n",
"subscriptions": [
"mechanic/scheduler/daily"
],
"subscriptions_template": "mechanic/scheduler/daily",
"tags": [
"Inventory",
"Schedule"
]
}