Publish a certain collection, daily, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Publish a certain collection, daily

Use this task with the companion unpublishing task (see this task's documentation) to make a certain collection of products available on a schedule, and unavailable on another schedule.

Runs Occurs every Monday at midnight (in local time), with a 9 hour delay, Occurs every Tuesday at midnight (in local time), with a 9 hour delay, Occurs every Wednesday at midnight (in local time), with a 9 hour delay, Occurs every Thursday at midnight (in local time), with a 9 hour delay, Occurs every Friday at midnight (in local time), with a 9 hour delay, Occurs every Saturday at midnight (in local time), with a 10 hour delay, and Occurs every Sunday at midnight (in local time), with a 10 hour delay. Configuration includes collection id.

15-day free trial – unlimited tasks

Documentation

Use this task with the companion unpublishing task (see this task's documentation) to make a certain collection of products available on a schedule, and unavailable on another schedule.

For best results, pair this task with Unpublish a certain collection, daily, from our task library.

To configure this task, enter the "Collection ID" for the collection you wish to publish. Refer to this article for assistance on finding Shopify object IDs.

Out of the box, this task will publish everything in this collection at 9am on weekdays, and 10am on weekends. To adjust this, click the "Show Advanced" link, and tweak the "Subscriptions" setting to taste. Each line represents midnight in your shop's local timezone, plus whatever number of hours you prefer. For example, mechanic/scheduler/tuesday+13.hours would mean Tuesday at 1pm.

Developer details

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?)

Open source
View on GitHub to contribute to this task
Subscriptions
mechanic/scheduler/monday+9.hours
mechanic/scheduler/tuesday+9.hours
mechanic/scheduler/wednesday+9.hours
mechanic/scheduler/thursday+9.hours
mechanic/scheduler/friday+9.hours
mechanic/scheduler/saturday+10.hours
mechanic/scheduler/sunday+10.hours
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
collection id (required)
Code
{% assign collection = shop.collections[options.collection_id__required] %}

{% if collection == blank and event.preview != true %}
  {% error message: "Collection ID does not exist in this shop. Refer to task notes for help on locating Shopify object IDs.", collection_id: options.collection_id__required %}
{% endif %}

{% capture query %}
  query {
    publications(first: 250) {
      edges {
        node {
          id
          name
        }
      }
    }
  }
{% endcapture %}

{% assign result = query | shopify %}

{% if event.preview %}
  {% capture result_json %}
    {
      "data": {
        "publications": {
          "edges": [
            {
              "node": {
                "id": "gid://shopify/Publication/1234567890",
                "name": "Online Store"
              }
            }
          ]
        }
      }
    }
  {% endcapture %}

  {% assign result = result_json | parse_json %}

  {% capture collection_json %}
    {
      "products": [
        {
          "admin_graphql_api_id": "gid://shopify/Product/1234567890"
        }
      ]
    }
  {% endcapture %}

  {% assign collection = collection_json | parse_json %}
{% endif %}

{% assign online_store_publication = result.data.publications.edges | map: "node" | where: "name", "Online Store" | first %}

{% for product in collection.products %}
  {% action "shopify" %}
    mutation {
      publishablePublish(
        id: {{ product.admin_graphql_api_id | json }}
        input: {
          publicationId: {{ online_store_publication.id | json }}
        }
      ) {
        userErrors {
          field
          message
        }
      }
    }
  {% endaction %}
{% endfor %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more