Can liquid interact via GraphQL endpoint?

Solved
Highlighted
Shopify Partner
29 0 2

hi dev theme fellows, I am pretty new to dev theme.  a friend of mine has an issue on sorting newest products on `whats-new` page.  Her workflow looks like this: she preps to release product in advance(about 2 weeks) by the time product get published(if it is future product Shopify does not provide date:( `published_at`) it is becoming not new one since it is sort by date created and product gets pushed down the list. From liquid file, it seems it is tight to `collections.sorting.` API. So the question is is there may be another way to tackle this issue may be via `tags`? Any thoughts guys on this?

 

This is snip from collection-sorting.liquid

 

    <option value="created-ascending">{{ 'collections.sorting.date_ascending' | t }}</option>

 

My thoughts on GraphQL is if I can stick the query request somehow there then I can sort based on the tag and do some manipulation.  I am not sure if it is possible and wanted to run by you. 

 

 

 

0 Likes
Highlighted

Success.

Shopify Expert
9852 98 1614

To answer your thread post specifically - no.

 

You can use Liquid to adjust the order of items in a collection but only for a paginated set. I've also seen this approached by just using a collection that has items added removed, or adding/removing tags to keep a collection full of just new things, or pulling in content and ordering with JavaScript, or adding items to a menu (linklist).

 

Not sure of the business process behind the scenes so hard to make any suggestion on how you might code it.

 

At least you know that you can not order an entire collection with Liquid. If you will only return at most 50 items then Liquid could help. More than that will need an alternate approach that might include the above.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
1 Like
Highlighted
Shopify Partner
29 0 2

Thanks @Jason !

0 Likes
Highlighted
Shopify Partner
1665 52 192

Without graphql , Admin+liquid wise prep the products into a holding collection with manual sort, or pre tag them, and update collection template to pull in those products after published. Feels like i'm missing part of the problem though.

 

Otherwise if your running the show with api and it's just a small set always could just dupe swap: make a new one -> confirm and cache -> and delete the old ones 

 

 

note to self confirm published_at updates.



 

Problem Solved? ✔️Accept the solution so you can help others.
Confused? Busy? ? Get me to solve it paull.newton+shopifyforum@gmail.com.
Buy me a coffee? ☕ paypal.me/paulnewton or donate to eff.org
0 Likes
Highlighted
Shopify Partner
29 0 2

thanks @PaulNewton  !

 

this is here point:

 

When you sort a collection by newest first, it pulls dates per creation of the item, not 
the item's publish date. This is a huge problem for all stores that upload new items frequently,
since we often write the listings in batches and schedule them to publish at regular intervals for efficiency. What store doesn't want a "New Items" collection? We get probably 90% of our sales from our New Items
collection, as our customers check our website every single Friday night to see what new inventory we've added.
The biggest problem comes when a vendor releases new items that we need to publish right away (early bird gets the worm),
or if we need to add something to a scheduled publish date after we've written items for other dates.
Items we've created earlier and scheduled to go live in the future get "buried" below the items we wrote and
published immediately, and stay buried. As a result, our sales plummet.
0 Likes
Highlighted

Success.

Shopify Partner
1665 52 192

 


@samwise wrote:

thanks @PaulNewton  !

 

this is here point:

 

When you sort a collection by newest first, it pulls dates per creation of the item, not 
the item's publish date.

Ahh of course, yeah your gonna wanna throw your hat in the feature request ring to support@shopify.com about getting either:

  • A) published_at exposed as an option collection.sort_options in liquid
  • B) published_at,etc made accessible in the liquid sort filter
  • C) published_at,etc made accessible on the product objects in liquid
  • D) metafields natively usable in the sort filter
  • E) a setting for collections that dictates what date sorting is supposed to represent on collections, unlikely

 

For the following keeping in mind jasons warnings about paginated objects, so you might get something that seems right but is actually hilariously wrong.

 

I haven't checked to see if it's exposed this way via the sort filter because normally you don't get at product.created_at in liquid

{% assign products = collection.products | sort: 'created_at' %}

Or a workaround might be to use the product.type set to "new",  or use the product.template suffix after applying an alternate template of "New" to the products

 

{% assign products = collection.products | sort: 'product.type' | reverse %} {% comment %} because "new" comes after nothing right? riight!?{% endcomment %}

 

{% assign products = collection.products | sort: 'template_suffix' | reverse %}

 

Also created and published are exposed in the ajax api json

Problem Solved? ✔️Accept the solution so you can help others.
Confused? Busy? ? Get me to solve it paull.newton+shopifyforum@gmail.com.
Buy me a coffee? ☕ paypal.me/paulnewton or donate to eff.org
1 Like
Highlighted
Shopify Partner
29 0 2

@PaulNewton  thanks so much! 

 

What u think if run by webhook when product is published update created_at with published_at? I haven't tried that but something can be done I guess. 

 

 

0 Likes
Highlighted
Shopify Partner
1665 52 192

@samwise wrote:

What u think if run by webhook when product is published update created_at with published_at?

 


/shrug by nature created_at isn't something i'd consider modifying so I've never tried.

Be interesting if you could document it

 

Problem Solved? ✔️Accept the solution so you can help others.
Confused? Busy? ? Get me to solve it paull.newton+shopifyforum@gmail.com.
Buy me a coffee? ☕ paypal.me/paulnewton or donate to eff.org
0 Likes
Highlighted
Shopify Partner
29 0 2

@PaulNewton  Tested on my dev store RestAPI and GraphQL do not support that.  :) 

 

 

 

0 Likes
Shopify Partner
53 1 3

You won't be able to interact via the GraphQL endpoint with Liquid. Pertaining to your issue, we recently added a feature to our app for the purpose of sorting your existing collections using publish date (or updated date, depending on your choice) - https://apps.shopify.com/advanced-custom-collections

 

Whenever a product is added / updated (which includes the product getting published upon reaching the set future date), there is a webhook request sent to the app which will then sort your collection accordingly. The whole process takes a few minutes for the sort to be reflected.

 

Do try it out, it has a 7 days free trial period =)

0 Likes