Reset inventory levels when they get too low with Mechanic.

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

Reset inventory levels when they get too low

by Isaac Bowen (team@usemechanic.com)

Use this task to automatically maintain a minimum inventory level.

Runs when an inventory level is updated. Configuration includes minimum inventory level, location, and product types to ignore.

15-day free trial – unlimited tasks

Documentation

To find your location ID, start by opening the locations settings in the Shopify admin. (Hint: Search the Shopify admin for "Locations".) Then, click on the location whose inventory levels you want to monitor. Your location ID is the series of numbers at the end of the location URL, in your browser's address bar. For example, if the URL is https://example.myshopify.com/admin/settings/locations/1234567890, the location ID is 1234568790.

To ignore certain products by their product type, fill in the "Product types to ignore" option with a comma-separated list (e.g. "Shirts, Hats").

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 inventory level is updated (shopify/inventory_levels/update)
Options
minimum inventory level (number, required), location (number), product types to ignore
Script
{% assign minimum_inventory_level = options.minimum_inventory_level__number_required %}

{% assign location_id_qualifies = false %}
{% if options.location_id__number == blank or inventory_level.location_id == options.location_id__number %}
  {% assign location_id_qualifies = true %}
{% endif %}

{% assign inventory_level_requires_reset = false %}
{% if location_id_qualifies and inventory_level.available < 0 %}
  {% assign inventory_level_requires_reset = true %}
{% endif %}

{% if inventory_level_requires_reset and options.product_types_to_ignore != blank %}
  {% assign product_types_to_ignore = options.product_types_to_ignore | replace: ", ", "," | split: "," %}
  {% assign product_type = inventory_level.variant.product.product_type %}
  {% if product_type != blank and product_types_to_ignore contains product_type %}
    {% assign inventory_level_requires_reset = false %}
  {% endif %}
{% endif %}

{% if inventory_level_requires_reset or event.preview %}
  {
    "action": {
      "type": "shopify",
      "options": [
        "post",
        "/admin/inventory_levels/set.json",
        {
          "inventory_item_id": {{ inventory_level.inventory_item_id | json }},
          "location_id": {{ inventory_level.location_id | json }},
          "available": {{ minimum_inventory_level | json }}
        }
      ]
    }
  }
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Minimum inventory level
0