Skip to content
πŸ‘€ See Sanity in action: Watch product demo now β†’
Sanity
Get started
  • Sanity Studio - Flexible editing environment
  • Content Lake - Real-time database
  • Developer experience - Tooling you love
  • Structured content - The philosophy behind Sanity
  • Review changes - View edits & rollback instantly
  • Image pipeline - On-demand transformations
  • E-commerce - Better shopping experiences
  • Marketing sites - Control your story
  • Products & services - Innovate and automate
  • Mobile apps - Content backend for every OS
  • Aether - Unique digital shopping experience
  • Morning Brew - Omnichannel media distribution
  • InVision - Delivering exceptional customer experiences
  • DataStax - Personalization for global audience
  • React
  • Gatsby
  • Next
  • Nuxt
  • Eleventy
  • Netlify
  • Vercel
  • Algolia
  • Documentation
  • Reference
  • Guides
  • Resource library
  • Headless CMS
  • Tools & plugins
  • Project showcase
  • Schemas & snippets
  • Agency partners
  • Technology partners
  • Get support
  • Share your work
  • Enterprise SSO
EnterprisePricing
Contact salesLog inGet started
Published May 3rd 2018

E-Commerce Sample Schema:

New e-commerce sample schema in `sanity init` πŸ›’ πŸ› πŸ†•

Even Eidsten Westvang

Even is a Sanity.io co-founder and product person

When you have set up a new project with `sanity init` you have had the choice between a simple film database and a blog. Our intention was to provide examples of how well known data structures are modeled in Sanity.

We've now added something slightly more substantial to sanity init: an e-commerce template.

Remember to npm install -g @sanity/cli before testing it out!

We've also made a frontend example in Vue.js and Nuxt.js with Snipcart that we're also writing up and will publish an article on in the coming days.

Transglobal Candy Store

When you install the schema you are given the choice to import some data as well – we've put together a little transglobal Candy Store with a few products, categories and vendors for you.

Yes, that's Swedish candy featuring hockey puck packaging and ammonium chloride powder.

What’s in the box

The template more or less follows the Shopify model for products and has the following bells and whistles.

Products

Products contain expected fields like:

  • Vendor
  • Categories
  • Tags
  • Description
  • Blurb

Remember, this is just what we ship this example with. If you need to extend the schema, just add your own fields and the studio will hot reload with your new fields.

Localization

Some fields, like blurb and title are localized. Have a look at /schema/supportedLanguages.js to change what languages are available:

export default [
  { id: 'en', title: 'English', isDefault: true },
  { id: 'es', title: 'Spanish' },
  { id: 'nb', title: 'Norwegian' }
]

Variants

Perhaps the missile batteries in your shop are available in a range of pastels? Products often come in a range of options with their own:

  • SKUs
  • Weight
  • Images
  • Descriptions

It’s therefore common to define an array of variants of a product.

We thought it would be nice to be able to specify base characteristics for all variants so there is a default variant on the product itself. Should you for example sync your data over to Shopify you could read the fields from the basic variant and overwrite fields from more specific variants.

Categories

Products can belong to multiple categories. Categories can belong to multiple categories as well. That way you can make both products and categories pop-up multiple places in your navigational structure. If you like pure taxonomies this will make your head hurt, but understandably it’s popular with e-commerce sites.

Barcodes!

We thought we should demonstrate how custom input components work as well. So in a fit of exuberance we added a barcode renderer to product. If you look in the plugins folder on the root of the project it should provide a simple example of how to build your own visual components for a datatype.

Try it out

To run your own custom tailored e-commerce backend install a fresh copy of Sanity:

Get started!

Poster image of shopping cart derived from Cart by Alfa design on the Noun Project.

Page content

  • Transglobal Candy Store
  • What’s in the box
    • Products
  • Localization
  • Variants
  • Categories
  • Barcodes!
  • Try it out

Platform

Structured ContentDeveloper experienceContent LakeSanity StudioSecurity & Compliance
  • Sanity vs Contentful
  • Sanity vs Strapi
  • Sanity vs Adobe Experience Manager
  • Sanity vs Hygraph
  • Sanity vs Sitecore
  • Sanity vs Storyblok
  • Sanity vs Contentstack
  • Sanity vs Prismic
  • Sanity vs Drupal

Resources

Documentation
  • React Blog
  • Gatsby Blog
  • Next.js Landing Pages
  • Progressive Web Application
  • Single Page Application
  • Svelte & Typescript App
  • Vue & Tailwind Blog
  • Developer Portfolio Templates
  • Form validation with Yup
  • Live Preview with Next.js and Sanity.io
Resource library
  • Agency partners
  • Technology partners
  • Blog Template
  • Personal Website Template
  • Developer Portfolio Templates
  • All Templates
Case Studies
  • Headless CMS
  • What is an API CMS
  • Static Sites 101
  • Headless SEO
  • Localization
  • GraphQL vs REST
  • What is a DXP?
  • Typescript 101
  • React CMS
  • Next.JS CMS
  • CMS for Shopify
  • Content platform
  • Multilingual CMS
  • Static Site CMS
  • Gatsby CMS
  • Node CMS
  • E-commerce CMS
  • Vue CMS
  • Angular CMS
  • GraphQL CMS
  • Newspaper CMS
  • Magazine CMS
  • Mobile apps CMS

Company

Contact SalesEnterpriseCareersTerms of ServiceAccessibility Statement

Stay connected

  • GitHub
  • Slack
  • Twitter
  • YouTube
  • Stack Overflow
  • Blog RSS
  • Newsletter
Β©Sanity 2023