Auto-tag products with their vendors, with Mechanic.

Mechanic is an automation development platform for Shopify. :)

Auto-tag products with their vendors

by Isaac Bowen (team@usemechanic.com)

Use this task to copy each product's vendor to the product's tag. :)

Runs when a product is created, when a product is updated, and when a user triggers the task.

15-day free trial – unlimited tasks

Documentation

Run this task manually to scan every product in your store. Otherwise, this task will run for specific products, whenever a product is created or updated.

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 product is created (shopify/products/create)
when a product is updated (shopify/products/update)
when a user triggers the task (mechanic/user/trigger)
Script
{% if event.preview %}
  {% action "shopify" %}
    mutation {
      tagsAdd(
        id: "gid://shopify/Product/1234576890"
        tags: "Nike"
      ) {
        userErrors {
          field
          message
        }
      }
    }
  {% endaction %}
{% endif %}

{% if event.topic == "mechanic/user/trigger" %}
  {% assign products = shop.products %}
{% elsif event.topic contains "shopify/products/" %}
  {% assign products = array %}
  {% assign products[0] = product %}
{% endif %}

{% for product in products %}
  {% if product.vendor == blank %}
    {% continue %}
  {% endif %}

  {% unless product.tags contains product.vendor %}
    {% action "shopify" %}
      mutation {
        tagsAdd(
          id: {{ product.admin_graphql_api_id | json }}
          tags: {{ product.vendor | json }}
        ) {
          userErrors {
            field
            message
          }
        }
      }
    {% endaction %}
  {% endunless %}
{% endfor %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.