Publish a certain collection, daily, with Mechanic.

Mechanic is a development 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 9 hours after every Monday at midnight, 9 hours after every Tuesday at midnight, 9 hours after every Wednesday at midnight, 9 hours after every Thursday at midnight, 9 hours after every Friday at midnight, 10 hours after every Saturday at midnight, and 10 hours after every Sunday at midnight. Configuration includes collection.

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, Gurus, 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.

Open source
View on GitHub to contribute to this task
Events
9 hours after every Monday at midnight (mechanic/scheduler/monday+9.hours)
9 hours after every Tuesday at midnight (mechanic/scheduler/tuesday+9.hours)
9 hours after every Wednesday at midnight (mechanic/scheduler/wednesday+9.hours)
9 hours after every Thursday at midnight (mechanic/scheduler/thursday+9.hours)
9 hours after every Friday at midnight (mechanic/scheduler/friday+9.hours)
10 hours after every Saturday at midnight (mechanic/scheduler/saturday+10.hours)
10 hours after every Sunday at midnight (mechanic/scheduler/sunday+10.hours)
Options
collection (required)
Script
{% 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 %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.