使用 Commerce Layer、Next.js、Sanity studio 构建的多国电子商务模板,已部署到 Netlify。
使用 Commerce Layer、Next.js、Sanity studio 构建的多国电子商务模板,已部署到 Netlify。
A multi-country ecommerce template built with Commerce Layer, Nextjs, Sanity studio, and deployed to Netlify. Want to learn more about how we built the first version of this template and how you can build yours? Then you should read this article on our blog.
/studio.Storefront (/ page) |
Sanity studio (/studio page) |
|---|---|
| Path | Description |
|---|---|
.env.local.example |
Example file with all the required environment variables. |
/components |
React components for the storefront. |
/locale/index.ts |
Config file for the storefront's transalations (en-US, it-IT, and fr-FR). |
/hooks/GetToken.ts |
React hook file to fetch a salesChannel token from Commerce Layer and save as a cookie. |
/pages/[countryCode]/[lang]/index.tsx |
Index page for the storefront (country selector and product listing). |
/pages/[countryCode]/[lang]/[product].tsx |
Page for all product items (image, product information, and variant selection). |
/pages/[countryCode]/[lang]/cart.tsx |
Cart page for for the storefront with link to checkout. |
/data |
Exported data to seed your Sanity studio with. |
/utils/sanity/api.ts |
Where all data from Sanity is fetched using groq queries. |
sanity.config.ts |
Config file for Sanity Studio. |
sanity.cli.ts |
Config file for Sanity CLI. |
/pages/studio/[[...index]].tsx |
Where Sanity Studio is mounted using next-sanity. |
/schemas |
Where Sanity Studio gets its content types from. |
/plugins |
Where the advanced Sanity Studio customization is setup. |
next.config.mjs |
Config file for Next.js. |
eslint.config.mjs |
ESLint flat config file for code linting. |
The quickest way to get up and running is to use the deploy button below to set up and deploy automatically to Netlify. Afterward, you will add some seed data to Commerce Layer and Sanity studio. The deploy button will clone this repository and ask you to enter all the required environment variables. Alternatively, you can clone this repository, configure the template, import the dataset into your Sanity studio, import some seed commerce data into your Commerce Layer organization, and deploy your application. The installation guides below will show you how to achieve this.
Clone this repository (learn how to do this).
Rename the .env.local.example file to .env.local and add the following credentials:
| Variable | Description |
|---|---|
BUILD_LANGUAGES |
The supported locales (the default is en-US, it-IT, fr-FR). |
NEXT_PUBLIC_SITE_NAME |
Optional name for the `` head tag (you can also edit this directly in the code). |
NEXT_PUBLIC_SITE_URL |
Optional URL of your deployed project for the og:url meta property (you can also edit this directly in the code). |
NEXT_PUBLIC_CL_CLIENT_ID |
Your Commerce Layer sales channels application client ID (you can create this automatically by following this onboarding guide or manually on the Commerce Layer dashboard. |
NEXT_PUBLIC_CL_ENDPOINT |
Your Commerce Layer organization's base endpoint (you can copy this on the Commerce Layer dashboard. |
NEXT_PUBLIC_SANITY_PROJECT_TITLE |
Optional name for the `` head tag in Sanity studio (you can also edit this directly in the code). |
NEXT_PUBLIC_SANITY_PROJECT_ID |
Sanity project ID (you can get this from sanity.io/manage after creating a new project with the npm create sanity@latest CLI command or this quick start wizard. |
NEXT_PUBLIC_SANITY_DATASET |
Sanity dataset (you can get this from sanity.io/manage). |
NEXT_PUBLIC_SANITY_API_VERSION |
Sanity API version in the ISO date format, e.g 2026-09-14 (you can learn more about this in Sanity docs). According to the docs this can be set to today's date in UTC format to get the latest features. |
NEXT_PUBLIC_SANITY_TOKEN |
Sanity API token (you can get this from sanity.io/manage). |
pnpm installpnpm run devThis will run the storefront at localhost:3000 and studio at localhost:3000/studio.
| Command | Description |
|---|---|
pnpm run build |
Builds the application for production. |
pnpm start |
Starts the production server (run pnpm run build first). |
pnpm run check |
Lints the codebase with ESLint. |
pnpm run check:fix |
Formats the codebase with Prettier and fixes the linting errors. |
pnpm run format |
Formats the codebase with Prettier. |
pnpm run export |
Exports the Sanity production dataset to /data. |
Create a free Commerce Layer account. If you already have an active account, kindly skip to Step 3.
Create a new organization or follow the onboarding tutorial guide.
Create a new Integrations application with Name set to CLI and Role set to admin.
In your newly created application, copy the Client ID, Client secret, and Base endpoint credentials.
Install the Commerce Layer CLI which is available as an npm package or yarn package using the command below:
//npm
npm install -g @commercelayer/cli
//yarn
yarn global add @commercelayer/cli暂无开放 Issues,或尚未同步最近议题。