This demo is an enhanced version of our AKVA demo, powered by Sanity + Hydrogen. This demo is compatible with @shopify/hydrogen ~= 1.3.0
.
Demo | Sanity Connect for Shopify
AKVA is our customized Hydrogen starter that presents a real-world example of how Sanity and Structured Content can elevate your custom Shopify storefronts. This is an enhanced version demonstrating some additional features such as enhanced structured content for products and the addition of a "guide" content type, all of which lead to richer PDPs (Product Display Pages). These additions include:
- A material document type to tell a story about the materials a product is made up of. A product can be composed of multiple materials. The PDP is updated to display this information as well as cross-sell other products made of the same material.
- A people document type allows details to be added for makers of the products. Again, this content is displayed on the PDP with a short biography and link through to the catalogue of the artists work.
- The guide document type is an example of how content and sales strategies can work together through structured content. If a guide references a product, then any hotspotted images are pulled onto any relevant PDPs in order to show products in context.
This demo also features an embedded version of our pre-configured Studio and Sanity Connect for Shopify, which syncs products and collections from your Shopify storefront to your Sanity dataset.
This starter showcases a few patterns you can adopt when creating your own custom storefronts. Use Sanity and Hydrogen to delight customers with rich, shoppable editorial experiences that best tell your story.
This studio is based on our Shopify Studio template, which has a number of features. In addition to this, we've modelled some additional content as detailed above.
This TypeScript demo adopts many of Hydrogen's framework conventions and third-party libraries. If you've used Hydrogen then you should hopefully feel at home here.
This demo comes with a custom useSanityQuery
hook that allows you to query your Sanity dataset directly from server components.
// MyServerComponent.server.jsx
import useSanityQuery from './hooks/useSanityQuery';
const QUERY = `*[_type == 'page' && slug.current == $slug]`;
const PARAMS = {slug: 'about'};
export default function MyServerComponent() {
const {data, error} = useSanityQuery({
// Required
query: QUERY,
// Optional
params: PARAMS,
// Optional: pass through any useQuery options
options: {
preload: false,
},
});
return <div>{JSON.stringify(data)}</div>;
}
The hook itself is super lightweight - it uses our official @sanity/client
library wrapped in a Hydrogen useQuery
hook to make it suspense-friendly. That's it!
We've taken the following opinions on how we've approached this demo.
Shopify is the source of truth for non-editorial content
- For products, this includes titles, handles, variant images and product options.
- For collections, this includes titles and collection images.
Shopify data stored in our Sanity dataset is used to improve the editor experience
- This allows us to display things like product status, prices and even inventory levels right in our Sanity Studio.
- Our application always fetches from Shopify's Storefront API at runtime to ensure we have the freshest data possible, especially important when dealing with fast-moving inventory.
Collections are managed entirely by Shopify
- Shopify is used to handle collection rules and sort orders. Sanity is used to enhance the content displayed on the storefront.
Product options are customized in Sanity
- Data added to specific product options (for example, associating a hex value with the color 'Red', or a string value with the Poster size 'A2') is done in Sanity.
- We treat this quite simply and manage these in a dedicated field within the
Settings
section of our studio. We also make sure to query this field whenever querying products in our Sanity dataset. - This could alternatively be managed with Shopify's metatags.
We don't surface Shopify HTML descriptions and metatags
- For this demo, Shopify tags are used purely as a non-visual organizational tool (to drive automated collections) and we use Portable Text over Shopify's description HTML field. However, Hydrogen makes it very easy to surface these in your application if needed.
Non-product (regular) pages are managed entirely by Sanity
- Shopify pages and blog posts (associated with the Online Store) channel aren't used in this demo. A dedicated
page
document type in Sanity has been created for this purpose.
We query our Sanity dataset when building sitemap.xml entries
- We use Sanity as the source of truth when determining whether a product or collection page is visible.
- This gives us the flexibility to add custom logic to control whether certain pages should be visible or not. For example, if you wanted to hide product pages within a specific date range, or hide collections that didn't have any editorial modules assigned to them.
- Node.js version 16.5.0 or higher
- Npm
These installation instructions assume you have already installed and configured Sanity Connect on your Shopify store.
-
Duplicate the
.env.example
file to.env
and replace the values to point to your Sanity project'sdataset
andprojectId
, and your Shopify storefront'sstoreDomain
andstorefrontToken
. Use Shopify's Headless app to manage tokens for the Storefront API. -
Install dependencies and start the development server
npm install npm run dev
-
Visit the development environment running at http://localhost:3000.
To run a local preview of your Hydrogen app in an environment similar to Oxygen, build your Hydrogen app and then run yarn preview
:
npm run build
npm run preview
npm run build
Then, you can run a local server.js
using the production build with:
npm run serve
See Hydrogen's documentation on deployment
This repository is published under the MIT license.