Hey All,
I am looking to store information on a variant (metafield or metaobject) that includes the following:
- VariantSelector
- Quantity
- Number
There will be multiple items of these, but each value should have (VariantSelector/Quantity/Number).
I thought about a metaobject with this as the structure, then a variant metafield (list) refering to the metaobject.
Just making sure this makes sense. I didnt want to have to load the records into a metaobject (due to maintenance), but couldn’t figure a way around without metaobjects.
I would probably create process to update metaobjects via an graphQL call (if its the only way)
Cheers,
Chris
Hi @ChrisBradley
Your instinct is correct - metaobject + variant metafield list reference is the right pattern. A few things worth considering before you build it out:
On the metaobject structure
Be deliberate about what VariantSelector actually is. If it’s a reference to another variant, use variant_reference type - don’t store it as text. This gives you referential integrity and means Shopify handles the join for you on the Storefront API. If the variant gets deleted, the reference returns null rather than leaving a dangling ID string you’ll debug six months later.
On the maintenance problem
The upsert pattern largely solves this - use a deterministic handle like variant-{variantId}-{index} so your sync process is idempotent. Run it as often as you like without tracking state. The real maintenance risk nobody mentions is orphaned metaobjects - when a variant is deleted, the metaobjects don’t cascade delete. Over time you’ll accumulate dead records. Build a cleanup job from day one, or at minimum log created handles so you can reconcile later.
On the list metafield
Be aware the list.metaobject_reference metafield has a 250 item limit. If your variant could ever have more than 250 of these {VariantSelector/Quantity/Number} entries, you’ll need a different approach - either pagination logic or storing the list on the metaobject itself rather than the variant.
The JSON alternative - when it’s actually fine
If this data is only ever read/written by your own backend (never queried via Storefront API, never filtered or sorted on), a json metafield is genuinely simpler and not a bad choice. The stigma against it is sometimes overstated. The problems start when you need to query by a field value or expose it to the storefront - then you’ll regret it.
Hey @Andrii_Hudimov
Thanks, I currently hold this as a json array somewhere else, but the team wants the ability to update or change the items easier, thus the change in process.
deterministic handle is a good call, thanks!
Do you mean you can only have 250 records within the object? I am well below that on a reference from a metafield.
What I do have is an issue where at times I will have a variant (referernce from the metaobject) where it could have a quantity of one or two. but i want to have a single reference for the variant but the ability to have a qty selector separately. same with price/discount on that particular variant from the metaobject. is that possible?
I have considered a workaround could a having a mixed reference, one that has SKU/QTY, one that has more and then the other for price overrides.
the name something like
{{SKU}}-{{QTY}} = SKU-1
{{SKU}}-{{QTY}} = SKU-2
{{SKU}}-{{QTY}}-{{OVERRIDE}} = SKU-1-100
@ChrisBradley This is interesting approach.
Hi @ChrisBradley yes, it’s possible.
Your metaobject holds the variant reference + quantity + price/discount as separate fields. One variant can appear in multiple metaobject records, each with different qty/price values. The parent variant’s metafield list then references all of them.
But we need to make sure the limitation of the metafield as well
@Andrii_Hudimov
It looks like the metaobject limit is 1,000,000 (Metaobject limits), so I should be able to do this all within a single metaobject and manage the entries within.
could be a little easier than digesting multiple references.
yes, that is right. It will be much easier
I think so @Andrii_Hudimov
Do you dont happen to know if you and create entries via graphQL mutation with gid: of variant?
do I just push value as gid (metaobjectCreate - GraphQL Admin)?
Yes, the GID is passed as a plain string value.
Shopify handles the type validation on the backend.
you can just pass the variant GID directly as the string value in the fields array.