A Next.js 13 and App Router-ready e-commerce template featuring:
- Next.js App Router
- Optimized for SEO using Next.js's Metadata
- React Server Components (RSCs) and Suspense
- Server Actions for mutations
- Edge Runtime
- New fetching and caching paradigms
- Dynamic OG images
- Styling with Tailwind CSS
- Checkout and payments with Saleor
- Automatic light/dark mode based on system settings
Note: Looking for Next.js Commerce v1? View the code, demo, and release notes.
Vercel is more than happy to partner and work with any commerce provider to help them get a similar template up and running and listed below. Alternative providers should be able to fork this repository and swap out the lib/…
files with their own implementation while leaving the rest of the template mostly unchanged.
You will need to use the environment variables defined in .env.example
to run Next.js Commerce. It's recommended you use Vercel Environment Variables for this, but a .env
file is all that is necessary.
Note: You should not commit your
.env
file or it will expose secrets that will allow others to control your Saleor store.
- Install Vercel CLI:
npm i -g vercel
- Link local instance with Vercel and GitHub accounts (creates
.vercel
directory):vercel link
- Download your environment variables:
vercel env pull
pnpm install
pnpm dev
Your app should now be running on localhost:3000.
Next.js Commerce requires a Saleor account.
Create a SALEOR_INSTANCE_URL
environment variable and use your Saleor GraphQL API URL as the value (ie. https://yourinstance.saleor.cloud/graphql/
).
Next.js Commerce utilizes Saleor's Storefront API to create unique customer experiences. The API offers a full range of commerce options making it possible for customers to control products, collections, menus, pages, cart, checkout, and more.
Utilizing Saleor's webhooks, and listening for selected Saleor webhook events, we can use Next'js on-demand revalidation to keep data fetches indefinitely cached until certain events in the Saleor store occur.
Next.js is pre-configured to listen for the following Saleor webhook events and automatically revalidate fetches.
CategoryCreated
CategoryDeleted
CategoryUpdated
CollectionUpdated
CollectionDeleted
CollectionCreated
ProductCreated
ProductDeleted
ProductUpdated
ProductVariantCreated
ProductVariantDeleted
ProductVariantUpdated
Expand to view detailed walkthrough
- Navigate to Configuration -> Webhooks `https://[your_saleor_subdomain].saleor.cloud/dashboard/custom-apps/add``.
- Name your app
Next.js Commerce
, addMANAGE_ORDERS
,MANAGE_DISCOUNTS
, andMANAGE_PRODUCTS
permissions and save. - Click on "Create Webhook" button.
- Name your webhook and add your Next.js Commerce URL with
/api/revalidate
. - Note: You don't need to add any "secrets" to the URL. Saleor uses public key encryption to verify the webhook is coming from your store.
- Copy and paste the subscription query at the bottom of the page and save.
The easiest way to test webhooks while developing locally is to use ngrok.
- Install and configure ngrok (you will need to create an account).
- Run your app locally,
npm run dev
. - In a separate terminal session, run
ngrok http 3000
. - Use the url generated by ngrok and add or update your webhook urls in Saleor.
Next.js Commerce is fully powered by Saleor in a truly headless and data-driven way.
https://yourinstance.saleor.cloud/dashboard/products/
Only Active
products are shown. Draft
products will not be shown until they are marked as Active
.
Product options and option combinations are driven by Saleor options and variants. When selecting options on the product detail page, other options and variant combinations will be visually validated and verified for availability, as Amazon does.
Products that are active and "out of stock" are still shown on the site, but the ability to add the product to the cart is disabled.
https://yourinstance.saleor.cloud/dashboard/collections/
Create whatever collections you want and configure them however you want. All available collections will show on the search page as filters on the left, with one exception...
Any collection names that start with the word "hidden" will not show up on the headless front end. The Next.js Commerce theme comes pre-configured to look for two hidden collections. Collections were chosen for this over tags so that order of products could be controlled (collections allow for manual ordering).
Create the following collections:
Featured
– Products in this collection are displayed in the three featured blocks on the homepage.All Products
– Products in this collection are displayed in the auto-scrolling carousel section on the homepage.
https://yourinstance.saleor.cloud/dashboard/pages/
Next.js Commerce contains a dynamic [page]
route. It will use the value to look for a corresponding page in Saleor. If a page is found, it will display its rich content using Tailwind's prose. If a page is not found, a 404 page is displayed.
https://yourinstance.saleor.cloud/dashboard/navigation/
Next.js Commerce's header and footer navigation is pre-configured to be controlled by Saleor navigation menus. This means you have full control over what links go here. They can be to collections, pages, external links, and more.
Create the following navigation menus:
navbar
– Menu items to be shown in the headless frontend header.footer
– Menu items to be shown in the headless frontend footer.
Saleor's products, collections, pages, etc. allow you to create custom SEO titles and descriptions. Next.js Commerce is pre-configured to display these custom values but also comes with sensible default fallbacks if they are not provided.