Mechanic is a development and ecommerce automation platform for Shopify. :)
Use this task to make a single product or page available for a limited window of time, on a monthly basis. Redirect your visitors to a specific page when that resource is unavailable.
Runs Occurs when a user manually triggers the task and Occurs every day at midnight (in local time). Configuration includes resource type, resource id, day of the month to publish resource, day of the month to unpublish resource, and redirect url when resource is not published.
Use this task to make a single product or page available for a limited window of time, on a monthly basis. Redirect your visitors to a specific page when that resource is unavailable.
Configure this task using the resource type (either "product" or "page"), a resource ID (learn how to find this), the days of the month for publishing and unpublishing, and the URL you'd like to send visitors to when they land on the resource when it's unpublished.
This task will run automatically, at midnight in your store's local timezone. Run this task manually, using the "Run task" button, if you'd like to test your settings immediately. :)
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/user/trigger mechanic/scheduler/daily
{% if options.resource_type__required != "product" and options.resource_type__required != "page" %} {"error": "Set 'Resource type' to either 'product' or 'page'."} {% endif %} {% assign dom = "now" | date: "%-d" | times: 1 %} {% assign resource_collection = options.resource_type__required | append: "s" %} {% assign resource = shop[resource_collection][options.resource_id__number_required] %} {% assign publish_dom = options.day_of_the_month_to_publish_resource__number_required %} {% assign unpublish_dom = options.day_of_the_month_to_unpublish_resource__number_required %} {% action "echo" resource_collection, resource.handle, resource.published_at, dom, publish_dom, unpublish_dom %} {% if publish_dom < unpublish_dom and publish_dom <= dom and dom < unpublish_dom %} {% assign should_be_published = true %} {% elsif unpublish_dom < publish_dom and publish_dom <= dom %} {% assign should_be_published = true %} {% elsif unpublish_dom < publish_dom and unpublish_dom <= dom and dom <= publish_dom %} {% assign should_be_published = false %} {% elsif publish_dom < unpublish_dom and unpublish_dom <= dom %} {% assign should_be_published = false %} {% elsif publish_dom < unpublish_dom and dom < publish_dom %} {% assign should_be_published = false %} {% endif %} {% action "echo" should_be_published %} {% if event.preview or should_be_published == true %} {% if resource.published_at != blank %} {"log": "Resource is already published; nothing to do."} {% else %} { "action": { "type": "shopify", "options": [ "update", [ {{ options.resource_type__required | json }}, {{ resource.id | json }} ], { "published": true } ] } } {% endif %} {% elsif should_be_published == false %} {% if resource.published_at == blank %} {"log": "Resource is already unpublished; nothing to do."} {% else %} { "action": { "type": "shopify", "options": [ "update", [ {{ options.resource_type__required | json }}, {{ resource.id | json }} ], { "published": false } ] } } {% endif %} {% endif %}
{% if options.redirect_url_when_resource_is_not_published != blank %} {% assign resource_collection = options.resource_type__required | append: "s" %} {% assign resource = shop[resource_collection][options.resource_id__number_required] %} if (document.title.match(/404 Not Found/) && window.location.pathname.match({{ "/" | append: options.resource_type__required | append: "s/" | append: resource.handle | json }})) { window.location.href = {{ options.redirect_url_when_resource_is_not_published | json }}; } {% endif %}
product