-
Notifications
You must be signed in to change notification settings - Fork 35
/
add-fulfillment-tracking-when-an-order-is-tagged.json
40 lines (40 loc) · 6.75 KB
/
add-fulfillment-tracking-when-an-order-is-tagged.json
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
{
"docs": "Configure this tag with a mapping of country codes to tracking companies and URL templates, and/or default companies and URL templates. When an order is tagged, this task will apply the appropriate values to each fulfillment that has a tracking number.\n\nConfigure this tag with mappings of two-character country codes to tracking companies, and tracking URL templates. Both companies and URL templates support a default value as well, which will be used for orders that don't have a mapped country in the task's configuration. When an order is tagged, this task will apply the appropriate values to each fulfillment that has a tracking number.\r\n\r\nIf \"Notify customers\" is enabled, this task will request that Shopify send a notification email when the fulfillment update is processed.",
"halt_action_run_sequence_on_error": false,
"name": "Add fulfillment tracking when an order is tagged",
"online_store_javascript": null,
"options": {
"order_tag_to_watch_for__required": "update-tracking",
"country_codes_and_tracking_url_templates__keyval": {
"US": "https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=TRACKING_NUMBER",
"CA": "https://www.canadapost.ca/trackweb/en#/search?searchFor=TRACKING_NUMBER",
"AU": "https://auspost.com.au/mypost/track/#/details/TRACKING_NUMBER",
"NZ": "https://www.nzpost.co.nz/tools/tracking/item/TRACKING_NUMBER",
"GB": "http://www.royalmail.com/portal/rm/track?trackNumber=TRACKING_NUMBER"
},
"default_tracking_url_template": "http://parcelsapp.com/en/tracking/TRACKING_NUMBER",
"overwrite_existing_tracking_urls__boolean": true,
"country_codes_and_tracking_companies__keyval": {
"US": "USPS",
"CA": "Canada Post",
"AU": "Australia Post",
"NZ": "New Zealand Post",
"GB": "Royal Mail"
},
"default_tracking_company": "Parcels",
"notify_customers__boolean": true
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% comment %}\n Preferred option order:\n\n {{ options.order_tag_to_watch_for__required }}\n {{ options.country_codes_and_tracking_url_templates__keyval }}\n {{ options.default_tracking_url_template }}\n {{ options.overwrite_existing_tracking_urls__boolean }}\n {{ options.country_codes_and_tracking_companies__keyval }}\n {{ options.default_tracking_company }}\n {{ options.notify_customers__boolean }}\n{% endcomment %}\n\n{% if options.country_codes_and_tracking_url_templates__keyval == blank and options.default_tracking_url_template == blank %}\n {% error \"Fill in at least one of 'Country codes and tracking URL templates' and 'Fallback tracking URL template'. :)\" %}\n{% endif %}\n\n{% for pair in options.country_codes_and_tracking_url_templates__keyval %}\n {% unless pair[1] contains \"TRACKING_NUMBER\" %}\n {% error %}{{ \"The template for \" | append: pair[0] | append: \" does not contain the placeholder 'TRACKING_NUMBER'. Please add it!\" | json }}{% enderror %}\n {% endunless %}\n{% endfor %}\n\n{% if options.default_tracking_url_template != blank %}\n {% unless options.default_tracking_url_template contains \"TRACKING_NUMBER\" %}\n {% error %}{{ \"The default template for does not contain the placeholder 'TRACKING_NUMBER'. Please add it!\" | json }}{% enderror %}\n {% endunless %}\n{% endif %}\n\n{% if event.preview %}\n {% capture order_json %}\n {\n \"tags\": {{ options.order_tag_to_watch_for__required | json }},\n \"shipping_address\": {\n \"country_code\": {{ options.country_codes_and_tracking_url_templates__keyval.first.first | json }}\n },\n \"fulfillments\": [\n {\n \"admin_graphql_api_id\": \"gid://shopify/Fulfillment/1234567890\",\n \"name\": \"#1234.1\",\n \"tracking_company\": \"Other\",\n \"tracking_number\": \"ABCDEF123456\",\n \"tracking_url\": null\n }\n ]\n }\n {% endcapture %}\n\n {% assign order = order_json | parse_json %}\n{% endif %}\n\n{% assign order_tags = order.tags | split: \", \" %}\n{% if order_tags contains options.order_tag_to_watch_for__required %}\n {% assign template = options.country_codes_and_tracking_url_templates__keyval[order.shipping_address.country_code] %}\n {% assign template = template | default: options.default_tracking_url_template %}\n\n {% for fulfillment in order.fulfillments %}\n {% if fulfillment.tracking_number == blank or fulfillment.tracking_number == \"false\" %}\n {% continue %}\n {% endif %}\n\n {% assign new_fulfillment_tracking_url = template | replace: \"TRACKING_NUMBER\", fulfillment.tracking_number %}\n {% assign new_fulfillment_tracking_company = options.country_codes_and_tracking_companies__keyval[order.shipping_address.country_code] | default: options.default_tracking_company | default: fulfillment.tracking_company %}\n\n {% if options.overwrite_existing_tracking_urls__boolean == false and fulfillment.tracking_url != blank %}\n {% log message: \"Fulfillment already has a tracking URL, and this task is configured not to overwrite, so we're sticking with the existing tracking URL\", new_fulfillment_tracking_url: new_fulfillment_tracking_url, fulfillment_tracking_url: fulfillment.tracking_url, fulfillment_name: fulfillment.name, fulfillment_id: fulfillment.id %}\n {% assign new_fulfillment_tracking_url = fulfillment.tracking_url %}\n {% endif %}\n\n {% if new_fulfillment_tracking_url == fulfillment.tracking_url and new_fulfillment_tracking_company == fulfillment.tracking_company %}\n {% log message: \"Tracking URL and company is unchanged; skipping this fulfillment\", fulfillment_tracking_company: fulfillment.tracking_company, fulfillment_tracking_url: fulfillment.tracking_url, fulfillment_name: fulfillment.name, fulfillment_id: fulfillment.id %}\n {% else %}\n {% action \"shopify\" %}\n mutation {\n fulfillmentTrackingInfoUpdateV2(\n fulfillmentId: {{ fulfillment.admin_graphql_api_id | json }}\n trackingInfoInput: {\n company: {{ new_fulfillment_tracking_company | json }}\n number: {{ fulfillment.tracking_number | json }}\n url: {{ new_fulfillment_tracking_url | json }}\n }\n notifyCustomer: {{ options.notify_customers__boolean | json }}\n ) {\n fulfillment {\n trackingInfo {\n company\n number\n url\n }\n }\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n {% endif %}\n {% endfor %}\n{% endif %}",
"subscriptions": [
"shopify/orders/updated"
],
"subscriptions_template": "shopify/orders/updated",
"tags": [
"Fulfillment",
"Tag",
"Tracking",
"Watch"
]
}