Free Shopify Collection Sorter

Build sorting rules for your Shopify collections (out-of-stock to the bottom, pinned products, best sellers, newest first) and run them every day on your own free Cloudflare Worker. No monthly app fee, and your token stays in your own account.

FreeNo signupData stays on your device

1. Describe your store and rules

Store
Collection 1

Deployment options

2. Your config and deploy steps

2 problem(s) found.

Fix these before deploying:

  • shop must be your permanent domain, e.g. "my-store.myshopify.com"
  • collections[0] needs a "handle" or an "id"

config.json

{
  "shop": "",
  "apiVersion": "2025-07",
  "collections": [
    {
      "handle": "",
      "sortBy": "newest",
      "tieBreaker": "title_az",
      "outOfStockToBottom": true
    }
  ]
}

Saved in this browser only. Nothing is sent anywhere.

Admin API scopes for your custom app

read_products, write_products, read_inventory

Paste into wrangler.toml

Put the config in [vars], or upload config.json to KV (see the steps below).

[vars]
SORTER_CONFIG = '''
{
  "shop": "",
  "apiVersion": "2025-07",
  "collections": [
    {
      "handle": "",
      "sortBy": "newest",
      "tieBreaker": "title_az",
      "outOfStockToBottom": true
    }
  ]
}
'''
[triggers]
crons = ["17 3 * * *"]

Free-plan request budget

Worst case 6 of 45 requests: everything fits in one run. A daily cron ("17 3 * * *") is enough.

  • (no handle): up to 5 requests

Deploy commands

  1. Get the Worker code and install

    cd workers/shopify-collection-sorter
    npm install
  2. Log in to Cloudflare (free account)

    npx wrangler login
  3. Store the Admin API token as a secret (paste shpat_… when asked)

    npx wrangler secret put SHOPIFY_ADMIN_TOKEN
  4. Optional: a long random key that protects the "run now" / dry-run endpoint

    npx wrangler secret put RUN_KEY
  5. Create the KV namespace, then paste its id into [[kv_namespaces]] in wrangler.toml

    npx wrangler kv namespace create SORTER_STATE
  6. Upload the config to KV (overrides SORTER_CONFIG in wrangler.toml)

    npx wrangler kv key put config --path config.json --binding SORTER_STATE --remote
  7. Deploy

    npx wrangler deploy

After creating the namespace, add this to wrangler.toml:

[[kv_namespaces]]
binding = "SORTER_STATE"
id = "<id printed by wrangler>"

Preview (dry run) and run now

curl -X POST -H "X-Run-Key: $RUN_KEY" "https://shopify-collection-sorter.<your-subdomain>.workers.dev/run?mode=dry"

# apply for real:
curl -X POST -H "X-Run-Key: $RUN_KEY" "https://shopify-collection-sorter.<your-subdomain>.workers.dev/run?mode=apply"

Why sort Shopify collections automatically?

The order of products in a collection decides what shoppers see first. When sold-out items sit at the top, new arrivals are buried on page three, or a best seller drifts down after a restock, conversion suffers. Shopify's built-in options sort by one thing only (best selling, price, date or title), and the moment you want "newest first, but out-of-stock at the bottom and these three products pinned", you are into manual drag-and-drop or a paid sorting app. Sorting apps on the Shopify App Store usually charge a monthly subscription, and plans for bigger catalogs can cost hundreds of dollars a month for what is, underneath, a scheduled API call.

This free Shopify collection sorter does the same job with a small open-source script that runs on your own Cloudflare account. It uses the official Shopify Admin GraphQL API, re-sorts your manual collections every day, and costs nothing on Cloudflare's free plan.

How to set up the free collection sorter, step by step

1. Build your rules

Use the form above. For each collection, enter its handle, pick a primary sort and a tie-breaker, and add the extras you need. The rules are applied in a fixed priority order: pinned products first (in the order you list them), then in-stock products sorted by tag boosts, the primary sort and the tie-breaker, then out-of-stock products sorted the same way, and finally products you pushed to the bottom.

2. Create a custom app in Shopify

In your Shopify admin go to Settings → Apps → Develop apps and create an app, or, if your store no longer offers that screen, create the app in the Shopify Dev Dashboard and install it on your store. Give it the Admin API scopes shown above (read_products, write_products,read_inventory, plus read_orders for best sellers over a date range). Install the app and copy the Admin API access token (starts with shpat_, shown only once), or note the client ID and secret for a Dev Dashboard app.

3. Deploy the Worker

The Worker code lives in the workers/shopify-collection-sorter folder of this project's repository. Paste your config into wrangler.toml, store the token withnpx wrangler secret put SHOPIFY_ADMIN_TOKEN, optionally create the KV namespace, and runnpx wrangler deploy. The commands panel above lists every step for your choices.

4. Preview, then let the cron run

With a RUN_KEY secret set, the curl command above returns a dry run: the current order, the new order and each product that would move. When it looks right, run it with mode=apply or just wait for the daily cron trigger.

Worked examples

Fashion store: new arrivals first, sold out last

Primary sort "Newest first", tie-breaker "Title A–Z", out-of-stock to the bottom, and a tag boostnew-arrival: 2. Products tagged new-arrival rise above everything else, the rest follow by creation date, and sold-out sizes sink to the end of the collection every morning.

Gift shop: best sellers of the last 30 days, with a hero product

Primary sort "Best selling, last N days" with 30 days, pin your hero product's handle to the top and push the gift card to the bottom. The Worker adds up units sold per product from your orders in that window, so seasonal winners move up quickly instead of an all-time ranking.

How it compares with paid Shopify sorting apps

Paid apps add a polished in-admin interface, merchandising analytics and support. This tool is deliberately small: rules live in a JSON config, sorting runs on a schedule rather than instantly, and you deploy it yourself with a few commands. In return it is free, you can read every line of code, only the minimum number of products is moved on each run, and your Shopify credentials never leave your own Cloudflare account.

Limits to know about

Frequently asked questions

Can I sort Shopify collections automatically for free?

Yes. This tool generates a configuration for a small Cloudflare Worker that you deploy to your own free Cloudflare account. A daily cron trigger re-sorts your manual collections through the Shopify Admin API, so there is no monthly app fee.

How do I push out-of-stock products to the bottom of a Shopify collection?

Tick "Move out-of-stock products to the bottom" for the collection. By default a product counts as out of stock when it tracks inventory and its total inventory is 0 or less; choose the exact mode to use variant availability instead, which respects "continue selling when out of stock".

Does the collection need to be sorted "Manually"?

Yes. Shopify only lets apps reorder products in collections whose sort order is Manually. Set it in the Shopify admin, or enable "Switch collections to manual sorting" and the Worker changes it for you via collectionUpdate.

Which API scopes does the custom app need?

read_products, write_products and read_inventory. Add read_orders only if you sort by best sellers over the last N days. Without read_all_orders, Shopify only returns orders from the last 60 days.

Is my Shopify access token safe?

The token is stored as an encrypted Cloudflare Worker secret with wrangler secret put. It never appears in the config, in this page, or in any HTTP response. The optional dry-run endpoint is locked behind your own RUN_KEY header.

What are the limits of the free Cloudflare plan?

A Worker on the free plan may make 50 outbound requests per run. The sorter keeps a budget (45 by default), sorts as many collections as fit and continues with the rest on the next run. Very large collections that need many moves at once may take several runs.

Can I preview the new order before anything changes?

Yes. Send a POST request to the Worker's /run endpoint with mode=dry and your RUN_KEY. It returns the current and the new order plus every position change, without writing to Shopify.

More free tools