Sanity v3 upgrade: Getting undefined error for products schema
I totally understand the pain of doing two major changes at once - that definitely makes debugging trickier! Let me help you figure out what's going on with your product schema for v3.
First, the good news: when using Sanity Connect for Shopify, the product data structure is actually handled automatically by the integration. You don't need to manually define a store object field in your schema - that's created automatically when Shopify products sync to your Sanity dataset.
What Actually Happens with Sanity Connect:
When you install and configure Sanity Connect for Shopify, it automatically creates product documents in your Sanity dataset. The Shopify data (title, variants, prices, etc.) appears in a read-only store property on these documents, but this is handled by the integration itself, not something you define in your schema.
Your Product Schema Should Look Like This for v3:
import {defineType, defineField} from 'sanity'
export default defineType({
name: 'product',
title: 'Product',
type: 'document',
fields: [
// Add your CUSTOM fields here - not the store object
defineField({
name: 'customDescription',
title: 'Custom Description',
type: 'text',
}),
defineField({
name: 'seo',
title: 'SEO',
type: 'object',
fields: [
{name: 'title', type: 'string'},
{name: 'description', type: 'text'}
]
})
// The 'store' object with Shopify data is added automatically
]
})Key v3 Migration Points:
- Use
defineTypeanddefineField- This is the v3 standard for better TypeScript support - Only define YOUR custom fields - Don't try to define the
storeobject - The
storeproperty appears automatically after sync completes
Common Causes of Your Undefined Error:
Initial sync hasn't completed - After connecting Sanity Connect, it takes time for products to sync. Check your Sanity project's "Connect" section to see sync status.
Accessing data incorrectly in queries - Shopify data lives under
store, so your GROQ queries need:*[_type == "product"]{ _id, "title": store.title, "slug": store.slug.current, "variants": store.variants, customDescription }Frontend code using wrong paths - Access
product.store.title, notproduct.titleSchema type name mismatch - Make sure your schema uses
name: 'product'(or whatever document type Sanity Connect is syncing to)
Quick Debugging Steps:
Check if products exist: Go to your Studio and look for product documents. Do they exist?
Inspect a product document: Open one and click the three dots → "Inspect" to see the raw JSON. You should see a
storeobject with Shopify data inside it.Verify the sync: In your Sanity project dashboard, check the Sanity Connect settings to confirm the sync is active and completed.
Check your query/component: Where exactly are you getting the undefined error? Share the specific code line and error message if you can - that'll help pinpoint whether it's a schema issue, query issue, or frontend rendering issue.
The most likely culprit is either that the initial sync hasn't finished yet, or your code is trying to access Shopify fields directly instead of through the store object. Let me know what you find when you inspect a product document!
Show original thread7 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.