-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathdelete-all-products.json
22 lines (22 loc) · 3.88 KB
/
delete-all-products.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"docs": "Use this task to quickly (and permanently) clear out your product list. Optionally, filter by a specific query, so as to only delete specific products from your store. Supports a test mode, allowing you to see exactly what products you can expect Mechanic to delete.\n\nUse this task to quickly clear out your product list.\r\n\r\n**Caution: if you leave the query option empty, this task will delete every product in your store.**\r\n\r\nUse the \"query\" setting to get specific about what products you want to delete. Tick the \"Test mode\" checkbox to verify which products will be deleted: after saving, use the \"Run task\" button to run the product scan, and you'll receive a list of products that Mechanic would have deleted in live mode. Once you're ready, uncheck the \"Test mode\" box and check the \"Live mode\" box, save the task, then use \"Run task\" to permanently delete all matching products.\r\n\r\nExample queries:\r\n\r\n* `product_type:Shirt`\r\n* `tag:old`\r\n\r\nLearn more:\r\n\r\n* [Supported query options](https://help.shopify.com/en/api/graphql-admin-api/reference/queryroot#products-2019-07)\r\n* [Query search syntax](https://help.shopify.com/api/getting-started/search-syntax)",
"halt_action_run_sequence_on_error": false,
"name": "Delete all products",
"online_store_javascript": null,
"options": {
"query": "",
"test_mode__boolean": true,
"live_mode__boolean": false
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% assign product_ids_and_titles = hash %}\n\n{% assign cursor = nil %}\n{% for n in (0..100) %}\n {% capture query %}\n query {\n products(\n first: 250\n after: {{ cursor | json }}\n sortKey: TITLE\n query: {{ options.query | json }}\n ) {\n pageInfo {\n hasNextPage\n }\n edges {\n cursor\n node {\n id\n title\n }\n }\n }\n }\n {% endcapture %}\n\n {% assign result = query | shopify %}\n\n {% if event.preview %}\n {% capture result_json %}\n {\n \"data\": {\n \"products\": {\n \"pageInfo\": {\n \"hasNextPage\": false\n },\n \"edges\": [\n {\n \"node\": {\n \"id\": \"gid://shopify/Product/1234567890\",\n \"title\": \"[sample product]\"\n }\n }\n ]\n }\n }\n }\n {% endcapture %}\n\n {% assign result = result_json | parse_json %}\n {% endif %}\n\n {% for product_edge in result.data.products.edges %}\n {% assign product_ids_and_titles[product_edge.node.id] = product_edge.node.title %}\n {% endfor %}\n\n {% if result.data.products.pageInfo.hasNextPage %}\n {% assign cursor = result.data.products.edges.last.cursor %}\n {% else %}\n {% break %}\n {% endif %}\n{% endfor %}\n\n{% if options.test_mode__boolean and options.live_mode__boolean %}\n {% error \"Please choose either test mode or live mode.\" %}\n{% elsif options.test_mode__boolean == false and options.live_mode__boolean == false %}\n {% error \"Please choose either test mode or live mode.\" %}\n{% elsif options.test_mode__boolean %}\n {% log products_found_count: product_ids_and_titles.size, products_found: product_ids_and_titles %}\n{% elsif options.live_mode__boolean %}\n {% for keyval in product_ids_and_titles %}\n {% action \"shopify\" %}\n mutation {\n productDelete(\n input: {\n id: {{ keyval[0] | json }}\n }\n ) {\n deletedProductId\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n {% endfor %}\n{% endif %}",
"subscriptions": [
"mechanic/user/trigger"
],
"subscriptions_template": "mechanic/user/trigger",
"tags": [
"Delete",
"Products"
]
}