Automatically deleting generated products
The products generated by the Sign Customiser are necessary for your users to purchase their customized products. Therefore, it is not possible to use Sign Customiser without generating products. However, we understand that this can be frustrating when viewing your product list. In this article, we will guide you on how to automatically delete these products using an app named Mechanic.
Please note that:
- The Mechanic app is separate from the Sign Customiser and requires a monthly fee of $9 to use.
- Please be aware that the Mechanic app performs the action of deleting your products, and therefore, you use it at your own risk. We cannot be held responsible if the app deletes any wanted products
Installing Mechanic
Go to the Mechanic app on the Shopify app store and choose "Add app".
Setting up
After installing the app, navigate to the Mechanic app dashboard on your Shopify dashboard, and then select 'Import tasks'.
On the following page, copy and paste this code to the Mechanic app and click 'Save new task'.
{"docs":"Use this task to automatically delete non-purchased products created by [Neon Sign Customiser](https://apps.shopify.com/neon-product-customiser). Set the number of days old products should be before Mechanic deletes a product.\n\nTick 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. \n\nOnce 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.\n\nCheck the run daily option to have the task run at 12AM daily.\n","halt_action_run_sequence_on_error":false,"name":"Delete non-purchased Sign Customiser auto-generated products older than X days","online_store_javascript":null,"order_status_javascript":null,"perform_action_runs_in_sequence":false,"script":"{% comment %}\n Options ordering:\n {{ options.products_must_be_x_number_of_days_old__number__required }} \n {{ options.test_mode__boolean }}\n {{ options.live_mode__boolean }} \n{% endcomment %}\n\n{% assign products_must_be_x_number_of_seconds_old = options.products_must_be_x_number_of_days_old__number__required | times: 24 | times: 60 | times: 60 %}\n\n{% assign products_age_threshold_s = \"now\" | date: \"%s\" | minus: products_must_be_x_number_of_seconds_old %}\n\n{% assign products_age_threshold_human = products_age_threshold_s | date: \"%Y-%m-%d %H:%M %:z\" %}\n\n{% assign products_age_threshold_date = products_age_threshold_s | date: \"%Y-%m-%d\" %}\n\n{% log %}{{ \"Threshold for deleteing products: \" | append: products_age_threshold_human | json }}{% endlog %}\n\n{% assign product_ids_and_titles = hash %}\n\n{% capture product_query -%}\n -tag:npc_ordered product_type:'Custom Neon' created_at:<{{ products_age_threshold_date }}\n{% endcapture %}\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: {{ product_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 %}","shopify_api_version":"2023-07","subscriptions_template":"mechanic/user/trigger\n{% if options.run_daily__boolean %}\n mechanic/scheduler/daily\n{% endif %}","subscriptions":["mechanic/user/trigger","mechanic/scheduler/daily"],"preview_event_definitions":[],"options":{"products_must_be_x_number_of_days_old__number__required":"7","test_mode__boolean":false,"live_mode__boolean":true,"run_daily__boolean":true}}
Back to the app's dashboard and enable the task.
The app will ask for more access to your store, click 'Grant access' to give permission.
You're all set! The unpurchased neon sign products will now be deleted automatically after 30 days.
Need help setting up? Feel free to drop us a message at support@neonproductcustomizer.com.