Mechanic is a development and ecommerce automation platform for Shopify. :)
Useful for enforcing order limits on the backend, use this task to ensure that too many of a certain product cannot be purchased. This task can be configured with multiple SKUs, too!
Runs Occurs whenever an order is created. Configuration includes skus to watch for, quantity threshold for cancellation, send cancellation email to customer, attempt to refund or void payment in full, and reason for cancellation.
Useful for enforcing order limits on the backend, use this task to ensure that too many of a certain product cannot be purchased. This task can be configured with multiple SKUs, too!
Notes:
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/orders/create
{% comment %} An opinion about option order: {{ options.skus_to_watch_for__required_array }} {{ options.quantity_threshold_for_cancellation__number_required }} {{ options.send_cancellation_email_to_customer__boolean }} {{ options.attempt_to_refund_or_void_payment_in_full__boolean }} {{ options.reason_for_cancellation__required }} {% endcomment %} {% assign valid_reasons = "customer,inventory,fraud,declined,other" | split: "," %} {% if options.reason_for_cancellation__required != blank %} {% unless valid_reasons contains options.reason_for_cancellation__required %} {"error": {{ valid_reasons | json | prepend: "'Reason for cancellation' must be one of " | json }}} {% endunless %} {% endif %} {% assign sku_count = 0 %} {% for line_item in order.line_items %} {% if line_item.sku != blank and options.skus_to_watch_for__required_array contains line_item.sku %} {% assign sku_count = sku_count | plus: line_item.quantity %} {% endif %} {% endfor %} {% if order.fulfillment_status == "fulfilled" or order.fulfillment_status == "partial" %} {% assign order_qualifies = false %} {% else %} {% assign order_qualifies = true %} {% endif %} {% if event.preview or sku_count >= options.quantity_threshold_for_cancellation__number_required %} {% if order_qualifies %} {% action "shopify" %} [ "post", "/admin/orders/{{ order.id }}/cancel.json", { {% if options.attempt_to_refund_or_void_payment_in_full__boolean %} {% capture refund_query %} query { order(id: {{ order.admin_graphql_api_id | json }}) { suggestedRefund(suggestFullRefund: true, refundShipping: true) { amountSet { shopMoney { amount currencyCode } } } } } {% endcapture %} {% assign refund_result = refund_query | shopify %} {% assign refund_money = refund_result.data.order.suggestedRefund.amountSet.shopMoney %} {% if event.preview %} {% assign refund_money = hash %} {% assign refund_money["amount"] = order.total_price %} {% assign refund_money["currencyCode"] = order.currency %} {% endif %} "amount": {{ refund_money.amount | json }}, "currency": {{ refund_money.currencyCode | json }}, {% endif %} "email": {{ options.send_cancellation_email_to_customer__boolean | json }}, "reason": {{ options.reason_for_cancellation__required | json }} } ] {% endaction %} {% endif %} {% endif %}
other