How can I sort products by price using a theme app extension?

Topic summary

Goal: Fetch all products and return JSON sorted by price or created time for use in an app.

Current working approach: A custom collection template (templates/collection.test.liquid) outputs JSON using Liquid and {% paginate collection.products by 25 %}, enabling sorting via the URL parameter sort_by=price-descending.

Constraint: The developer cannot ship or create custom theme templates for merchants, so this approach isn’t viable for an app. They ask if a Theme App Extension can provide the same functionality.

Attempted alternative: Using Liquid to access collection[“all”].products and loop over products. Limitation observed: only the first 50 products are returned, so any sorting affects only that subset.

Key questions:

  • Can a Theme App Extension expose a similar JSON endpoint and support pagination/sorting?
  • How to retrieve and sort the full product set without custom templates, given Liquid’s product retrieval limits?

Status: No solution or guidance provided yet; the issue remains open.

Summarized with AI on January 7. AI used: gpt-5.

Hi,

I am developing an app for which I was trying to fetch the products and sort them on the basis of price, and created time. So I created a collection template and made the request to it. I named this ‘templates/collection.test.liquid’.

{% layout none %}
{% capture productsJson %}
  {% paginate collection.products by 25 %}
    {{ collection.products | json }}
  {% endpaginate %}
{% endcapture %}
{{ productsJson }}

Then to get products sorted by price descending I would make a fetch request from shop to this link

https://some-kind-of-example.myshopify.com/collections/all?view=test&sort_by=price-descending

and I will get the JSON data.

Now the problem is when app will be created I had to create this template for user. But I can’t as it is not allowed.

Can I do the same thing with theme app extension ?

I have tried to get the liquid code in this way

{% assign allProducts = collection["all"].products %}
{% for product in allProducts %}
{{ product.title }}
{% endfor %}

but this code only fetches the first 50 products. And if try to sort them, it will just do the sorting in those products.
I need help regarding this.