Auto-tag orders that contain bundles with Mechanic.

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

Auto-tag orders that contain bundles

by Isaac Bowen (team@usemechanic.com)

Use this task to automatically detect and tag orders that contain a complete bundle of products. Configure this task with as many bundles as you like, specifying a tag to add and a list of required SKUs.

Runs when an order is created. Configuration includes tags and required skus.

15-day free trial – unlimited tasks

Documentation

Fill in "Tags and required SKUs" option with tags on the left, and a comma-delimited lists of SKUs on the right.

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 created (shopify/orders/create)
Options
tags and required skus (keyval, required)
Script
{% assign tags_to_save = order.tags %}
{% assign order_skus = order.line_items | map: "sku" | uniq %}

{% for pair in options.tags_and_required_skus__keyval_required %}
  {% assign tag = pair[0] %}
  {% assign required_skus = pair[1] | split: "," %}

  {% assign matched_sku_count = 0 %}
  {% for order_sku in order_skus %}
    {% if required_skus contains order_sku %}
      {% assign matched_sku_count = matched_sku_count | plus: 1 %}
    {% endif %}
  {% endfor %}

  {% if event.preview or matched_sku_count == required_skus.size %}
    {% assign tags_to_save = tags_to_save | add_tag: tag %}
  {% endif %}
{% endfor %}

{% if event.preview or tags_to_save != order.tags %}
  {
    "action": {
      "type": "shopify",
      "options": [
        "update",
        [
          "order",
          {{ order.id | json }}
        ],
        {
          "tags": {{ tags_to_save | json }}
        }
      ]
    }
  }
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Tags and required skus
{"Summer bundle"=>"SUN01,SUN02,SUN03", "Winter bundle"=>"SNOW01,SNOW02,SNOW03"}