TIL when creating collections

Solved
HunkyBill
Shopify Expert
4353 36 462

I use code to open a session with a Shopify store. It has a modest number of SKUs, about 5000.

 

I use some basic GraphQL code to set up a new collection, with 4 rules. One rule is to ensure only inventory with a suitable quantity gets added to the collection, another is to ensure products of certain types do not get in. Using code to generate a collection, hey that is simple!

 

Here is the kicker, or the reason for this TIL

 

When I used the Shopify Admin to navigate to Products -> Collections, and I opened up this new collection, everything I coded in my GraphQL mutation was respected, except the Product box was empty, save for a small message banner. The message was from Shopify, and it said: Products are not yet available. They are being built so check back in a few minutes.

 

As a programmer on the other end of the situation, I was expecting to be able to do this:

 

  1. create a collection with rules
  2. when I get back the good word that I succeeded, open up the collection and use the products

I was not expecting that if I opened the collection, it could have ZERO products in it. How do I deal with that? What is the signal that the collection is not only created but built?

 

Do I have to set a timer for 1 minute in my code to SLEEP and wait? If I ask the collection for the number of products, what if it truly is zero? What if the zero just signifies it is not built? How long is too long to wait?

 

So much in question here. Any advice Shopify team?

 

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
_JB
Shopify Staff
Shopify Staff
750 86 163

Hey @HunkyBill,

 

Definitely understand the concern here, and we're actually in the process of moving away from the current system which can create delays in smart collection builds for stores with larger product catalogs.

 

In the 2020-01 API version we started laying the groundwork for this change, by introducing new endpoints to access products in collections directly (rather than going through the collect resource). Once all the new APIs are in place to support this change, the collect resource will be fully deprecated and this will allow smart collections to be built in real time. More information about these changes is available in Jan 2020 release notes here.

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
HunkyBill
Shopify Expert
4353 36 462

So you are saying that in the future, if I were to create a smart collection "ZAZAZA", and the rules dictated that 437 of 7689 products were in it, I could point the product resource picker at the collection I just created, and it would populate with the 437 products, no delay incurred because Shopify internally is fixed, and no longer needs to slowly build the smart collection?

 

I am not clear on that. I could care a less about Collects... I realize that is part of the problem, but I am not touching them in this scenario.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
_JB
Shopify Staff
Shopify Staff
750 86 163

This is an accepted solution.

So you are saying that in the future, if I were to create a smart collection "ZAZAZA", and the rules dictated that 437 of 7689 products were in it, I could point the product resource picker at the collection I just created, and it would populate with the 437 products, no delay incurred because Shopify internally is fixed, and no longer needs to slowly build the smart collection?

 

Yes this is correct, I guess I could've provided more detail here. So the delay you see right now is caused mainly by the existence of collects. When a smart collection is configured the system recalculates the relationship between each collection/collect/product, and the process of creating/destroying collect resources and writing these to the database is what causes the delay. We've started the process of moving away from reliance on collects, and once all features have been migrated the collect resource will be fully deprecated, allowing products in smart collections to appear in real-time.

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog