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:
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?
Solved! Go to the solution
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.
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.
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.