Mechanic is a development and ecommerce automation platform for Shopify. :)
This task watches for newly-created collections, waits a configurable number of days, and then sends a staff email if no orders have been placed for products that are in the new collection.
Runs Occurs whenever a collection is created, with a 2 day delay. Configuration includes email recipient, email subject, email body, and days to wait before checking.
Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, everybody.
That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.
(By the way, have you seen our documentation? Have you joined the Slack community?)
shopify/collections/create+{{ options.days_to_wait_before_checking__number_required | default: 2 }}.days
{% assign collection_created_at_s = collection.created_at | date: "%s" | times: 1 %} {% assign collection_has_orders = false %} {% assign cursor = nil %} {% assign total_inventory = 0 %} {% for n in (0..10000) %} {% capture query %} query { orders( first: 10 after: {{ cursor | json }} sortKey: CREATED_AT reverse: true ) { edges { node { id createdAt lineItems( first: 45 ) { edges { node { product { inCollection(id: {{ collection.admin_graphql_api_id | json }}) } } } } } } } } {% endcapture %} {% assign result = query | shopify %} {% for order_edge in result.data.orders.edges %} {% assign order = order_edge.node %} {% assign products_in_order = order.lineItems.edges | map: "node" | map: "product" %} {% for product in products_in_order %} {% if product.inCollection %} {% assign collection_has_orders = true %} {% break %} {% endif %} {% endfor %} {% endfor %} {% if collection_has_orders %} {% break %} {% endif %} {% assign last_order_created_at_s = result.data.orders.edges.last.node.createdAt | date: "%s" | times: 1 %} {% if last_order_created_at_s <= collection_created_at_s %} {% break %} {% endif %} {% if result.data.orders.pageInfo.hasNextPage %} {% assign cursor = result.data.orders.edges.last.cursor %} {% else %} {% break %} {% endif %} {% endfor %} {% if event.preview or collection_has_orders == false %} {% action "email" %} { "to": {{ options.email_recipient__required_email | json }}, "subject": {{ options.email_subject__required | json }}, "body": {{ options.email_body__required_multiline | newline_to_br | json }}, "reply_to": {{ shop.customer_email | json }}, "from_display_name": {{ shop.name | json }} } {% endaction %} {% endif %}
The new collection "{{ collection.title }}" has no orders yet
Hello, The collection "<a href="https://{{ shop.domain }}/collections/{{ collection.handle }}">{{ collection.title }}</a>" was created on {{ collection.created_at | date: "%Y-%m-%d" }}, and no orders have yet been made for products in this collection. Thanks, Mechanic, for {{ shop.name }}
2