Skip to content
Sanity
    • Platform

      Sanity Studio

      Flexible editing environment

      APIs

      Connect to anything

      Content Lake

      Real-time database

      Try product demo

      Features

      Real-time collaboration

      Fearlessly work with content

      Precise content querying

      Treat content as data with GROQ

      Localization

      Coherent messaging across territories

    • Use cases

      E-commerce

      Richer shopping experiences

      Marketing sites

      Control your story

      Products & services

      Innovate and automate

      Mobile apps

      Content backend for every OS

      View all

      Integrations

      Shopify
      Mux
      Vercel
      Netlify
      Algolia
      Cloudinary
      BigCommerce
      Commerce Layer
      Smartling
      Transifex
      View all
    • Learn

      Documentation
      Studio API Reference
      API reference
      Guides
      GROQ cheat sheet
      Sanity UI
      Get started

      Build and share

      Templates
      Tools and plugins
      Schemas and snippets
      Project showcase
      Share your work
      Browse Exchange

      Frameworks

      React
      Vue
      Next.js
      Nuxt.js
      Svelte
      Remix
      Gatsby
      Astro
      Angular
      Eleventy
      View all
    • Discover

      Blog
      Resource library
      Agency partners
      Become a partner
      Technical support
      Talk to sales

      Case studies

      Puma

      Source of truth for global markets

      Aether

      Unique digital shopping experience

      Morning Brew

      Omnichannel media distribution

      InVision

      Delivering exceptional customer experiences

      View all

      Popular guides

      Headless CMS
      Structured content
      Content modeling
      Headless SEO
      Static websites
      View all
    • Enterprise
    • Pricing
    • Log in
    • Contact sales
    • Get started
Contact salesGet started
Published May 3rd 2018

E-Commerce Sample Schema:

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

Even Eidsten Westvang

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

Product

Sanity StudioAPIsContent LakeSecurity & Compliance
  • Sanity vs Contentful
  • Sanity vs Strapi
  • Sanity vs Wordpress
  • Sanity vs Adobe Experience Manager
  • Sanity vs Hygraph
  • Sanity vs Sitecore
  • Sanity vs Storyblok
  • Sanity vs Contentstack
  • Sanity vs Prismic
  • Sanity vs Drupal
  • Sanity vs ButterCMS

Resources

DocumentationBlogResource libraryCase Studies
  • React Blog
  • Gatsby Blog
  • Next.js Landing Pages
  • Making a PWA
  • Single Page Application
  • Svelte & Typescript App
  • Vue & Tailwind Blog
  • Developer Portfolio Templates
  • Form validation with Yup
  • Live Preview with Next.js and Sanity.io
  • Next.js blog
  • Next.js personal website
  • Clean Next.js + Sanity app
  • Clean Remix + Sanity app
  • Clean SvelteKit + Sanity app
  • All Templates
  • Agency partners
  • Technology partners
  • Headless CMS 101
  • Static Sites 101
  • Headless Commerce 101
  • CMS for enterprise
  • Headless SEO
  • Localization
  • Content as a Service
  • What is a DXP?
  • Typescript 101
  • Ecommerce SEO
  • What is a Composable DXP?
  • What is an API?
  • GraphQL vs REST
  • React CMS
  • Next.JS CMS
  • CMS for Shopify
  • API-first CMS
  • Content platform
  • Multilingual CMS
  • Static Site CMS
  • Gatsby CMS
  • Node CMS
  • E-commerce CMS
  • Vue CMS
  • Angular CMS
  • GraphQL CMS
  • Newspaper CMS
  • Magazine CMS
  • CMS for apps
  • Remix CMS
  • Nuxt CMS
  • SvelteKit CMS
  • Agile CMS
  • Eleventy CMS

Company

Contact SalesEnterpriseCareersTerms of ServicePrivacy PolicyAccessibility Statement

Stay connected

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