Auto-connect new products to all locations, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Auto-connect new products to all locations

Using Shopify's multi-locations feature, and importing products in bulk? Use this task to automatically connect each new product to every location for your store.

Runs Occurs whenever a product is created. Configuration includes track inventory using shopify and allow orders for out of stock products.

15-day free trial – unlimited tasks

Developer details

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?)

Open source
View on GitHub to contribute to this task
Subscriptions
shopify/products/create
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
track inventory using shopify (boolean), allow orders for out of stock products (boolean)
Code
{% if event.preview %}
  {
    "action": {
      "type": "shopify",
      "options": [
        "post",
        "/admin/inventory_levels/connect.json",
        {
          "inventory_item_id": 1234567890,
          "location_id": 1234567890,
          "relocate_if_necessary": false
        }
      ]
    }
  }
{% else %}
  {% for variant in product.variants %}
    {% for location in shop.locations %}
      {
        "action": {
          "type": "shopify",
          "options": [
            "post",
            "/admin/inventory_levels/connect.json",
            {
              "inventory_item_id": {{ variant.inventory_item_id | json }},
              "location_id": {{ location.id | json }},
              "relocate_if_necessary": false
            }
          ]
        }
      }
    {% endfor %}
  {% endfor %}
{% endif %}

{% if event.preview or options.track_inventory_using_shopify__boolean or options.allow_orders_for_out_of_stock_products__boolean %}
  {
    "action": {
      "type": "shopify",
      "options": [
        "update",
        [
          "product",
          {{ product.id | json }}
        ],
        {
          "variants": [
            {% for variant in product.variants %}
              {
                "id": {{ variant.id | json }},
                "inventory_management": {% if options.track_inventory_using_shopify__boolean %}"shopify"{% else %}null{% endif %},
                "inventory_policy": {% if options.allow_orders_for_out_of_stock_products__boolean %}"continue"{% else %}"deny"{% endif %}
              }{% unless forloop.last %},{% endunless %}
            {% endfor %}
          ]
        }
      ]
    }
  }
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Track inventory using shopify
true
Allow orders for out of stock products
true