Client thinks sorting product collections cant be done programmatically

dylancam90
Shopify Partner
6 0 1

I know this cant be done using liquid because I have already tried. They want new items to appear first which contain a certain product tag and the on sale items to appear last in every custom collection on the site. 

 

I started creating a standalone app and plan to query the active products in the collection, reorder them, and then organize them using collectionReorderProducts in the GraphQL Admin API. The only thing I am worried about is there are up to 3k products in each collection and dont want to hit the rate limit. 

 

Other than that it seems to be possible but they said they reached out to multiple agencies that said it couldnt be done. Am I wrong or can this be done? 

Replies 2 (2)

race_
Shopify Partner
3 0 0

 

You should be able to do it in liquid. Or at least in javascript! 

I know i'm coming in to this with no context of what you've done so far, but here is my guess at what you can do with liquid. 

Note: This is not working with any filtering off tags yet. That can be added later. 

 

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

{% if sorted_products != blank %}
  <div class="product-list">
    {% for product in sorted_products %}
      <div class="product-item">
        <a href="{{ product.url }}">
          <div class="product-image">
            <img src="{{ product.featured_image | img_url: 'medium' }}" alt="{{ product.title }}">
          </div>
          <div class="product-title">{{ product.title }}</div>
        </a>
      </div>
    {% endfor %}
  </div>
{% else %}
  <p>No products found.</p>
{% endif %}

 

 


Let me know if this is anything close to what you have tried. I'm always looking for tricky code things that need a solution! 😂 

 

dylancam90
Shopify Partner
6 0 1

No liquid/JS wont work. Just because it was created/published at a certain date in my case doesn't mean that its new... JS is too slow and the pagination makes it impossible for either of those options. The only solution I think its to create a server to schedule sorts at night with the API.