🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Understanding the relationship between options, values, and variants in Sanity Connect.

2 replies
Last updated: Apr 11, 2022
Wondering if the Sanity Connect app would be able to give variant IDs for Option values. The current implementation is a bit problematic I think, seeing as if I had multiple Options and some of these Options had values with the same name, I’m not sure there is anyway to distinguish them? Unless index remains the same, but this feels very brittle to me.
e.g. with the below, this is tricky:


options:[
  {
    _key: 'Blue'
    _type: 'option'
    name: 'Blue'
    values: [
      'Signed',
      'Unsigned,
    ]
  },
  {
    _key: 'Red'
    _type: 'option'
    name: 'Red'
    values: [
      'Signed',
      'Unsigned,
    ]
  },
}
Whereas this would’ve been helpful:

options:[
  {
    _key: 'Blue'
    _type: 'option'
    name: 'Blue'
    values: [
      { 
        name: 'Signed', 
        variantId: 'schloop-doop-de-boop'
      },
      { 
        name: 'Unsigned', 
        variantId: 'turtle-burtle-plip-plop'
      },
    ]
  },
  {
    _key: 'Red'
    _type: 'option'
    name: 'Red'
    values: [
      { 
        name: 'Signed', 
        variantId: 'frump-de-bump-kerplunk'
      },
      { 
        name: 'Unsigned', 
        variantId: 'wiggle-fig-kerfloop'
      },
    ]
  },
}
Apr 10, 2022, 5:15 PM
I haven’t used Sanity Connect but isn’t the second one impossible since a variant is a combination of the option values? eg. In your example would the product have two drop downs, one for “Blue” and one for “Red”, both with the choice of “Signed” and “Unsigned”? In that case variant id is a result of the possible combinations. Or am I misunderstanding?
Regardless you can use
variantBySelectedOptions
to turn options/values back into a variant also: https://shopify.dev/api/storefront/2022-04/objects/Product#connections
Apr 10, 2022, 5:35 PM
Ahh thanks Cory nope you’re brilliant – sounds like this is a misunderstanding on my part then!
I was under the impression Variants were 1:1 with Options, but now I realise why that wouldn’t make sense... I can see that for every possible configuration of Options there would need to be a variant created and the point towards
variantBySelectedOptions
is exactly what I needed!
Thanks so much
Apr 11, 2022, 10:24 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?