Tag products with no images
Running manually or on a schedule, this task scans all products in your store, and adds a tag to any products that have no images. Optionally, choose to have this task remove that tag from any products that are found to have an image.
Try this taskWhen it runs
- Occurs when a user manually triggers the task
- Occurs when a bulk operation is completed
What you choose
- Product tag to add
- Remove product tag if images are found
- Run every 10 minutes
- Run hourly
- Run daily
Task code and subscriptions
You can edit the Liquid code after installing this task. View on GitHub or ask a question in the Mechanic Slack community.
Subscriptions
mechanic/user/trigger
{% if options.run_every_10_minutes__boolean %}
mechanic/scheduler/10min
{% elsif options.run_hourly__boolean %}
mechanic/scheduler/hourly
{% elsif options.run_daily__boolean %}
mechanic/scheduler/daily
{% endif %}
mechanic/shopify/bulk_operation
How task subscriptions work
Option types and flags
- Product tag to add (required)
- Remove product tag if images are found (boolean)
- Run every 10 minutes (boolean)
- Run hourly (boolean)
- Run daily (boolean)
Task code
{% if event.topic == "mechanic/user/trigger" or event.topic contains "mechanic/scheduler/" %}
{% capture bulk_operation_query %}
query {
products {
edges {
node {
__typename
id
tags
images {
edges {
node {
__typename
id
}
}
}
}
}
}
}
{% endcapture %}
{% action "shopify" %}
mutation {
bulkOperationRunQuery(
query: {{ bulk_operation_query | json }}
) {
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}
{% endaction %}
{% elsif event.topic == "mechanic/shopify/bulk_operation" %}
{% if event.preview %}
{% capture bulkOperation_objects_jsonl %}
{"__typename":"Product","id":"gid:\/\/shopify\/Product\/1234567890","tags":[]}
{% endcapture %}
{% assign bulkOperation = hash %}
{% assign bulkOperation["objects"] = bulkOperation_objects_jsonl | parse_jsonl %}
{% endif %}
{% assign products = bulkOperation.objects | where: "__typename", "Product" %}
{% assign images = bulkOperation.objects | where: "__typename", "Image" %}
{% for product in products %}
{% assign product_images = images | where: "__parentId", product.id %}
{% if product_images.size == 0 %}
{% unless product.tags contains options.product_tag_to_add__required %}
{% action "shopify" %}
mutation {
tagsAdd(
id: {{ product.id | json }}
tags: {{ options.product_tag_to_add__required | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endunless %}
{% else %}
{% if product.tags contains options.product_tag_to_add__required and options.remove_product_tag_if_images_are_found__boolean %}
{% action "shopify" %}
mutation {
tagsRemove(
id: {{ product.id | json }}
tags: {{ options.product_tag_to_add__required | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
Mechanic Liquid reference