Built by

abmenzel

Category

CMS

Version

2.0.0

Last updated

Jul 23, 2023, 18:36:51 PMa year 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 clipboardlocaleString and Copy to clipboardlocaleBlock 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 clipboardmedusa-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 clipboardtitle
  • Copy to clipboardsubtitle
  • Copy to clipboarddescription
  • Copy to clipboardhandle
  • Copy to clipboardtype
  • Copy to clipboardtags
  • Copy to clipboardcollection
  • Copy to clipboardthumbnail
  • Copy to clipboardimages
  • Copy to clipboardvariants
  • Copy to clipboardoptions
The plugin will sync the following fields from Sanity to Medusa on update:
  • Copy to clipboardtitle
  • Copy to clipboardsubtitle
  • Copy to clipboardhandle
  • Copy to clipboardthumbnail
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.