Essentially, I run a store that sells both embroidered and non-embroidered (blank) polos. I am attempting to write a script that runs every thirty minutes or so that will allow customers to order the embroidered polo if the blank is in stock but the pre-embroidered one is not. Thanks in advance if anyone can point me to the right resources or help me with this--I would be extremely grateful!
Pseudo-code would look something like this:
- Query products with a specific tag (something like "embroidery")
- For each product:
- Lookup the blank product based on metafield
- For each variant in product:
- Lookup the corresponding variant on the blank product
- If corresponding blank variant inventory > 0:
- Set oversell for that variant to true
- else:
- Set oversell for that variant to false
The result would be that each variant would be in one of four states:
- Pre-embroidered variant is in-stock and blank is in-stock: allowed to oversell, appears in-stock on the website
- Pre-embroidered variant is in-stock and blank is out-of-stock: not allowed to oversell, appears in-stock on the website.
- Pre-embroidered variant is out-of-stock and blank is in-stock: allowed to oversell, appears in-stock on the website.
- Pre-embroidered variant is out-of-stock and blank is out-of-stock: not allowed to oversell, appears out-of-stock on the website.