Archive orders on delivery with Mechanic.

Mechanic is the one-tool-does-it-all automation app for Shopify. :)

Archive orders on delivery

by Isaac Bowen (team@usemechanic.com)

Don't keep your customers waiting! Stay on top of orders that have yet to be delivered, by auto-archiving every order once every item has reached the customer.

Runs when a fulfillment event is created.

15-day free trial – unlimited tasks

Documentation

This task monitors fulfillment events. Every time a fulfillment event occurs, every fulfillment in the related order is scanned - once each fulfillment reaches the "delivered" status, this task archives the order.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Gurus, 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.

Events
when a fulfillment event is created (shopify/fulfillment_events/create)
Script
{% assign order_qualifies = false %}
{% assign order = fulfillment_event.order %}

{% if order.closed_at == blank %}
  {% if order.fulfillment_status == "fulfilled" %}
    {% assign shipment_statuses = order.fulfillments | map: "shipment_status" | uniq %}

    {% if shipment_statuses.size == 1 and shipment_statuses.first == "delivered" %}
      {% assign order_qualifies = true %}
    {% else %}
      {"log": {{ shipment_statuses | join: ", " | prepend: "Order is not fully delivered. Status(es) found: " | json }}}
    {% endif %}
  {% else %}
    {"log": {{ "Order is not fulfilled; status is " | append: order.fulfillment_status | json }}}
  {% endif %}
{% else %}
  {"log": "Order is already closed."}
{% endif %}

{% if order_qualifies or event.preview %}
  {
    "action": {
      "type": "shopify",
      "options": [
        "post",
        "/admin/orders/{{ order.id | default: "0000" }}/close.json",
        {}
      ]
    }
  }
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.