Mechanic is a development and ecommerce automation platform for Shopify. :)
This task manages your published product catalog, checking for the presence of a "preorder" tag, or a tag that starts with "preorder_" (like "preorder_summer"). If this tag is found, the task updates the product to allow customers to purchase the product after it's out of stock. If no preorder tag is found, the task makes sure customers cannot purchase the product if it's out of stock.
Runs Occurs every day at midnight (in local time) and Occurs when a user manually triggers the task.
This task manages your published product catalog, checking for the presence of a "preorder" tag, or a tag that starts with "preorder_" (like "preorder_summer"). If this tag is found, the task updates the product to allow customers to purchase the product after it's out of stock. If no preorder tag is found, the task makes sure customers cannot purchase the product if it's out of stock.
This task scans your product catalog nightly or when you hit the "Run task" button, checking for the presence of a "preorder" tag, or a tag that starts with "preorder_" (like "preorder_summer"). If this tag is found, the task updates the product to allow customers to purchase the product after it's out of stock. If no preorder tag is found, the task makes sure customers cannot purchase the product if it's out of stock.
Notes:
This task supports four event topics:
mechanic/scheduler/daily
for a daily scan, at midnight.mechanic/user/trigger
to run the task on-demand, with the push of a button.shopify/products/create
to run the task for each product as it's created.shopify/products/update
to run the task for each product as it's updated.Out of the box, the task comes configured with mechanic/scheduler/daily
and mechanic/user/trigger
. Use the "Subscriptions" setting (under "Show Advanced", in the task editor) to swap out subscriptions as needed.
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?)
mechanic/scheduler/daily mechanic/user/trigger
{% if event.preview %} { "action": { "type": "shopify", "options": [ "update", [ "variant", 12345 ], { "inventory_policy": "continue" } ] } } {% elsif event.topic == "shopify/products/create" or event.topic == "shopify/products/update" %} {% if product.published_at == blank %} {"log": "Product is not published; skipping scan"} {% else %} {% assign updated_variants_count = 0 %} {% assign product_updated = false %} {% assign product_tags = product.tags | split: ", " %} {% assign allow_preorders = false %} {% for tag in product_tags %} {% assign tag_parts = tag | split: "_" %} {% if tag_parts[0] == "preorder" %} {% assign allow_preorders = true %} {% break %} {% endif %} {% endfor %} {% assign inventory_policy_update = nil %} {% for variant in product.variants %} {% if allow_preorders and variant.inventory_policy == "deny" %} {% assign inventory_policy_update = "continue" %} {% elsif allow_preorders == false and variant.inventory_policy == "continue" %} {% assign inventory_policy_update = "deny" %} {% endif %} {% if inventory_policy_update %} {% assign product_updated = true %} {% assign updated_variants_count = updated_variants_count | plus: 1 %} { "action": { "type": "shopify", "options": [ "update", [ "variant", {{ variant.id | json }} ], { "inventory_policy": {{ inventory_policy_update | json }} } ] } } {% endif %} {% endfor %} {% capture log_message %} {{ product.variants.size }} variants scanned, {{ updated_variants_count }} variants required an update {% endcapture %} {"log": {{ log_message | strip | json }}} {% endif %} {% else %} {% assign products_count = 0 %} {% assign updated_products_count = 0 %} {% assign updated_variants_count = 0 %} {% for product in shop.products.published %} {% assign product_updated = false %} {% assign product_tags = product.tags | split: ", " %} {% assign allow_preorders = false %} {% for tag in product_tags %} {% assign tag_parts = tag | split: "_" %} {% if tag_parts[0] == "preorder" %} {% assign allow_preorders = true %} {% break %} {% endif %} {% endfor %} {% assign inventory_policy_update = nil %} {% for variant in product.variants %} {% if allow_preorders and variant.inventory_policy == "deny" %} {% assign inventory_policy_update = "continue" %} {% elsif allow_preorders == false and variant.inventory_policy == "continue" %} {% assign inventory_policy_update = "deny" %} {% endif %} {% if inventory_policy_update %} {% assign product_updated = true %} {% assign updated_variants_count = updated_variants_count | plus: 1 %} { "action": { "type": "shopify", "options": [ "update", [ "variant", {{ variant.id | json }} ], { "inventory_policy": {{ inventory_policy_update | json }} } ] } } {% endif %} {% endfor %} {% assign products_count = products_count | plus: 1 %} {% if product_updated %} {% assign updated_products_count = updated_products_count | plus: 1 %} {% endif %} {% endfor %} {% capture log_message %} {{ products_count }} published products scanned, {{ updated_products_count }} products ({{ updated_variants_count }} variants) required an update {% endcapture %} {"log": {{ log_message | strip | json }}} {% endif %}