Archive orders when fulfilled with Mechanic.

Mechanic is an automation and development platform for Shopify. :)

Archive orders when fulfilled

by Isaac Bowen (team@usemechanic.com)

Super simple: this task monitors for order fulfillments, and automatically archives orders when they're fulfilled.

Runs when an order is fulfilled and when a user triggers the task.

15-day free trial – unlimited tasks

Documentation

This task runs automatically, when orders are fulfilled. To scan your store's order history and archive all existing fulfilled orders, use the "Run task" button. Enable "Read all orders" to make sure Mechanic can scan your entire order history, and not just the last 60 days.

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 an order is fulfilled (shopify/orders/fulfilled)
when a user triggers the task (mechanic/user/trigger)
Script
{% if event.topic == "mechanic/user/trigger" %}
  {% if event.preview %}
    {
      "action": {
        "type": "shopify",
        "options": [
          "post",
          "/admin/orders/1234567890/close.json",
          {}
        ]
      }
    }
  {% else %}
    {% for order in shop.orders.any.shipped.open %}
      {
        "action": {
          "type": "shopify",
          "options": [
            "post",
            "/admin/orders/{{ order.id | default: "1234567890" }}/close.json",
            {}
          ]
        }
      }
    {% endfor %}
  {% endif %}
{% elsif event.topic == "shopify/orders/fulfilled" %}
  {% if order.closed_at == blank or event.preview %}
    {
      "action": {
        "type": "shopify",
        "options": [
          "post",
          "/admin/orders/{{ order.id | default: "1234567890" }}/close.json",
          {}
        ]
      }
    }
  {% endif %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.