Mechanic is a development and ecommerce automation platform for Shopify. :)
This task runs when products are updated, checking if they have a description, and tagging them if not. Once a description has been added, then the tag will be removed.
Runs Occurs whenever a product is updated, ordered, or variants are added, removed or updated and Occurs when a user manually triggers the task. Configuration includes tag to apply.
This task runs when products are updated, checking if they have a description, and tagging them if not. Once a description has been added, then the tag will be removed.
You may also run the task manually to scan your entire product catalog,
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?)
shopify/products/update mechanic/user/trigger
{% assign tag_to_apply = options.tag_to_apply__required %}
{% assign products = array %}
{% if event.topic == "shopify/products/update" %}
{% capture query %}
query {
product(id: {{ product.admin_graphql_api_id | json }}) {
id
descriptionHtml
tags
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% assign products[0] = result.data.product %}
{% elsif event.topic == "mechanic/user/trigger" %}
{% assign cursor = nil %}
{% for n in (1..200) %}
{% capture query %}
query {
products(
first: 250
after: {{ cursor | json }}
) {
pageInfo {
hasNextPage
endCursor
}
nodes {
id
descriptionHtml
tags
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% assign products
= result.data.products.nodes
| default: array
| concat: products
%}
{% if result.data.products.pageInfo.hasNextPage %}
{% assign cursor = result.data.products.pageInfo.endCursor %}
{% else %}
{% break %}
{% endif %}
{% endfor %}
{% endif %}
{% if event.preview %}
{% assign products[0] = hash %}
{% assign products[0]["id"] = "gid://shopify/Product/1234567890" %}
{% endif %}
{% for product in products %}
{% if product.descriptionHtml == blank %}
{% unless product.tags contains tag_to_apply %}
{% action "shopify" %}
mutation {
tagsAdd(
id: {{ product.id | json }}
tags: {{ tag_to_apply | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endunless %}
{% elsif product.tags contains tag_to_apply %}
{% action "shopify" %}
mutation {
tagsRemove(
id: {{ product.id | json }}
tags: {{ tag_to_apply | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}
{% endfor %}