Built by

abmenzel

Category

CMS

Version

2.0.0

Last updated

Jul 23, 2023, 18:36:51 PM10 months ago

Sanity CMS

Manage the content of your storefront with Sanity CMS.

From v1 to v2

I've changed the plugin to use internationalizedArrayString instead of
Copy to clipboard
localeString
and
Copy to clipboard
localeBlock
for any fields using that format. This means that you will have to migrate your existing data to the new format if you want to use v2.

Features

  • Handle the presentational content of your commerce application using Sanity.
  • One-way sync from Medusa to Sanity, allowing you to add additional content through Sanity
  • Benefit from Sanity's advanced CMS features such as localization.

Prerequisites


Sanity File Plugin

This plugin assumes that the Sanity File Plugin is also being used, as it relies on this functionality for storing images.

How to Install

1. Copy the schemas from data/schemas to your Sanity project. (You can add to these schemas to suit your needs.)
2. Run the following command to install the plugin on your Medusa backend:
yarn add medusa-plugin-sanity
3. Set the following environment variables in
Copy to clipboard
.env
:
SANITY_PROJECT_ID=<YOUR_SANITY_PROJECT_ID>
SANITY_DATASET=<YOUR_SANITY_DATASET>
SANITY_TOKEN=<YOUR_SANITY_TOKEN>
3. In
Copy to clipboard
medusa-config.js
, :
plugins = [
//...
{
resolve: `medusa-plugin-sanity`,
options: {
projectId: process.env.SANITY_PROJECT_ID,
dataset: process.env.SANITY_DATASET,
token: process.env.SANITY_TOKEN,
apiVersion: '2021-10-21',
useCdn: false, // `false` if you want to ensure fresh data
},
},
]

Localization

This plugin assumes that you are using Sanity's field-level localization. The Sanity schema that comes with the plugin is already set up to support this. The schema assumes enligsh as the default language, and this is the field that is synced with Medusa.

Synchronization

The plugin will sync the following fields from Medusa to Sanity on creation/update:
  • Copy to clipboard
    title
  • Copy to clipboard
    subtitle
  • Copy to clipboard
    description
  • Copy to clipboard
    handle
  • Copy to clipboard
    type
  • Copy to clipboard
    tags
  • Copy to clipboard
    collection
  • Copy to clipboard
    thumbnail
  • Copy to clipboard
    images
  • Copy to clipboard
    variants
  • Copy to clipboard
    options
The plugin will sync the following fields from Sanity to Medusa on update:
  • Copy to clipboard
    title
  • Copy to clipboard
    subtitle
  • Copy to clipboard
    handle
  • Copy to clipboard
    thumbnail
Deleting a product in Medusa will also delete the corresponding document in Sanity, but not the other way around.

TODO

  • Add support for automatically creating types in Sanity
  • Add check for Sanity File Plugin
  • Add check for correct types in Sanity
  • Add support for migrating existing medusa product to Sanity

Build your own plugins

Develop your own plugins with our API to speed up your processes.

Make your plugin available via npm for it to be shared in our Plugin Library with the broader Medusa community.