• Stars
    star
    11,287
  • Rank 2,953 (Top 0.06 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Next.js Commerce

Deploy with Vercel

Next.js Commerce

A Next.js 13 and App Router-ready ecommerce 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 Shopify
  • Automatic light/dark mode based on system settings

Note: Looking for Next.js Commerce v1? View the code, demo, and release notes

Providers

Vercel will only be actively maintaining a Shopify version as outlined in our vision and strategy for Next.js Commerce.

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/shopify file with their own implementation while leaving the rest of the template mostly unchanged.

Running locally

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 Shopify store.

  1. Install Vercel CLI: npm i -g vercel
  2. Link local instance with Vercel and GitHub accounts (creates .vercel directory): vercel link
  3. Download your environment variables: vercel env pull
pnpm install
pnpm dev

Your app should now be running on localhost:3000.

Expand if you work at Vercel and want to run locally and / or contribute
  1. Run vc link.
  2. Select the Vercel Solutions scope.
  3. Connect to the existing commerce-shopify project.
  4. Run vc env pull to get environment variables.
  5. Run pmpm dev to ensure everything is working correctly.

How to configure your Shopify store for Next.js Commerce

Next.js Commerce requires a paid Shopify plan.

Note: Next.js Commerce will not work with a Shopify Starter plan as it does not allow installation of custom themes, which is required to run as a headless storefront.

Add Shopify domain to an environment variable

Create a SHOPIFY_STORE_DOMAIN environment variable and use your Shopify domain as the the value (ie. SHOPIFY_STORE_SUBDOMAIN.myshopify.com).

Note: Do not include the https://.

Accessing the Shopify Storefront API

Next.js Commerce utilizes Shopify'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.

In order to use the Shopify's Storefront API, you need to install the Headless app in your Shopify store.

Once installed, you'll need to create a SHOPIFY_STOREFRONT_ACCESS_TOKEN environment variable and use the public access token as the value

Note: Shopify does offer a Node.js Storefront API SDK. We use the Storefront API via GraphQL directly instead of the Node.js SDK so we have more control over fetching and caching.

Expand to view detailed walkthrough
  1. Navigate to https://SHOPIFY_STORE_SUBDOMAIN.myshopify.com/admin/settings/apps.
  2. Click the green Shopify App Store button. Shopify App Store
  3. Search for Headless and click on the Headless app. Headless
  4. Click the black Add app button. Add app
  5. Click the green Add sales channel button. Add sales channel
  6. Click the green Create storefront button. Create storefront
  7. Copy and paste the public access token and assign it to a SHOPIFY_STOREFRONT_ACCESS_TOKEN environment variable. Pubic access token
  8. If you ever need to reference the public access token again, you can navigate to https://SHOPIFY_STORE_SUBDOMAIN.myshopify.com/admin/headless_storefronts.

Install a headless theme

When using a headless Shopify setup, you normally don't want customers to access any of the theme pages except for checkout. However, you can't totally disable the theme and a lot of links will still point to the theme (e.g. links in emails, order details, plugins, checkout, etc.).

To enable a seamless flow between your headless site and Shopify, you can install the Shopify Headless Theme.

Follow the installation instructions and configure the theme with your headless site's values.

Expand to view detailed walkthrough
  1. Download Shopify Headless Theme. Download Shoify Headless Theme
  2. Navigate to https://SHOPIFY_STORE_SUBDOMAIN.myshopify.com/admin/themes.
  3. Click Add theme, then Upload zip file. Upload zip file
  4. Select the downloaded zip file from above, and click the green Upload file button. Select and upload file
  5. Click Customize. Customize theme
  6. Click Theme settings (ie. the paintbrush icon), expand the STOREFRONT section, enter your headless store domain, click the gray Publish button. Set headless domain in theme settings
  7. Confirm the theme change by clicking the green Save and publish button. Confirm save and publish
  8. The headless theme should now be your current active theme. Headless theme is current and active

Branding & Design

Since you're creating a headless Shopify store, you'll be in full control of your brand and design. However, there are still a few aspects we're leaving within Shopify's control.

  • Checkout
  • Emails
  • Order status
  • Order history
  • Favicon (for any Shopify controlled pages)

You can use Shopify's admin to customize these pages to match your brand and design.

Expand to view detailed walkthrough

Checkout, order status, and order history

  1. Navigate to https://SHOPIFY_STORE_SUBDOMAIN.myshopify.com/admin/settings/checkout.
  2. Click the green Customize button. Customize
  3. Click Branding (ie. the paintbrush icon) and customize your brand. Please note, there are three steps / pages to the checkout flow. Use the dropdown to change pages and adjust branding as needed on each page. Click Save when you are done. Branding
  4. Navigate to https://SHOPIFY_STORE_SUBDOMAIN.myshopify.com/admin/settings/branding.
  5. Customize settings to match your brand. Branding

Emails

  1. Navigate to https://SHOPIFY_STORE_SUBDOMAIN.myshopify.com/admin/settings/email_settings.
  2. Customize settings to match your brand. Branding

Favicon

  1. Navigate to https://SHOPIFY_STORE_SUBDOMAIN.myshopify.com/admin/themes.
  2. Click the green Customize button. Customize theme
  3. Click Theme settings (ie. the paintbrush icon), expand the FAVICON section, upload favicon, then click the Save button. Favicon

Configure webhooks for on-demand incremental static regeneration (ISR)

Utilizing Shopify's webhooks, and listening for select Shopify webhook event topics, we can use Next'js on-demand revalidation to keep data fetches indefinitely cached until certain events in the Shopify store occur.

Next.js is pre-configured to listen for the following Shopify webhook events and automatically revalidate fetches.

  • collections/create
  • collections/delete
  • collections/update
  • products/create
  • products/delete
  • products/update (this also includes when variants are added, updated, and removed as well as when products are purchased so inventory and out of stocks can be updated)
Expand to view detailed walkthrough

Setup secret for secure revalidation

  1. Create your own secret or generate a random UUID.
  2. Create a Vercel Environment Variable named SHOPIFY_REVALIDATION_SECRET and use the value from above.

Configure Shopify webhooks

  1. Navigate to https://SHOPIFY_STORE_SUBDOMAIN.myshopify.com/admin/settings/notifications.
  2. Add webhooks for all six event topics listed above. You can add more sets for other preview urls, environments, or local development. Append ?secret=[SECRET] to each url, where [SECRET] is the secret you created above. Shopify store webhooks Shopify store add webhook

Testing webhooks during local development

The easiest way to test webhooks while developing locally is to use ngrok.

  1. Install and configure ngrok (you will need to create an account).
  2. Run your app locally, npm run dev.
  3. In a separate terminal session, run ngrok http 3000.
  4. Use the url generated by ngrok and add or update your webhook urls in Shopify. ngrok Shopify store edit webhook
  5. You can now make changes to your store and your local app should receive updates. You can also use the Send test notification button to trigger a generic webhook test. Shopify store webhook send test notification

Using Shopify as a CMS

Next.js Commerce is fully powered by Shopify in a truly headless and data driven way.

Products

https://SHOPIFY_STORE_SUBDOMAIN.myshopify.com/admin/products

Only Active products are shown. Draft products will not be shown until they are marked as Active.

Active products can still be hidden and not seen by navigating the site, by adding a nextjs-frontend-hidden tag on the product. This tag will also tell search engines to not index or crawl the product. The product is still directly accessible via url. This feature is great for "secret" products you only want to people you share the url with.

Product options and option combinations are driven from Shopify options and variants. When selecting options on the product detail page, other option and variant combinations will be visually validated and verified for availability, like 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.

Collections

https://SHOPIFY_STORE_SUBDOMAIN.myshopify.com/admin/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:

  • Hidden: Homepage Featured Items -- Products in this collection are displayed in the three featured blocks on the homepage.
  • Hidden: Homepage Carousel -- Products in this collection are displayed in the auto-scrolling carousel section on the homepage.

Shopify collections

Shopify collection detail

Pages

https://SHOPIFY_STORE_SUBDOMAIN.myshopify.com/admin/pages

Next.js Commerce contains a dynamic [page] route. It will use the value to look for a corresponding page in Shopify. 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.

Shopify pages

Shopify page detail

Navigation menus

https://SHOPIFY_STORE_SUBDOMAIN.myshopify.com/admin/menus

Next.js Commerce's header and footer navigation is pre-configured to be controlled by Shopify 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:

  • Next.js Frontend Header Menu -- Menu items to be shown in the headless frontend header.
  • Next.js Frontend Footer Menu -- Menu items to be shown in the headless frontend footer.

Shopify navigation menus

Shopify navigation menu detail

SEO

Shopify'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.

Shopify SEO

More Repositories

1

next.js

The React Framework
JavaScript
126,710
star
2

hyper

A terminal built on web technologies
TypeScript
43,324
star
3

swr

React Hooks for Data Fetching
TypeScript
30,461
star
4

turborepo

Build system optimized for JavaScript and TypeScript, written in Rust
Rust
25,810
star
5

pkg

Package your Node.js project into an executable
JavaScript
24,260
star
6

vercel

Develop. Preview. Ship.
TypeScript
12,555
star
7

satori

Enlightened library to convert HTML and CSS to SVG
TypeScript
11,019
star
8

micro

Asynchronous HTTP microservices
TypeScript
10,525
star
9

ai

Build AI-powered applications with React, Svelte, Vue, and Solid
TypeScript
9,836
star
10

serve

Static file serving and directory listing
TypeScript
9,208
star
11

ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
JavaScript
9,063
star
12

styled-jsx

Full CSS support for JSX without compromises
JavaScript
7,677
star
13

ai-chatbot

A full-featured, hackable Next.js AI chatbot built by Vercel
TypeScript
6,579
star
14

nextjs-subscription-payments

Clone, deploy, and fully customize a SaaS subscription application with Next.js.
TypeScript
6,499
star
15

platforms

A full-stack Next.js app with multi-tenancy and custom domain support. Built with Next.js App Router and the Vercel Domains API.
TypeScript
5,650
star
16

ms

Tiny millisecond conversion utility
TypeScript
4,912
star
17

og-image

Open Graph Image as a Service - generate cards for Twitter, Facebook, Slack, etc
TypeScript
4,051
star
18

next-learn

Learn Next.js Starter Code
TypeScript
3,710
star
19

release

Generate changelogs with a single command
JavaScript
3,558
star
20

examples

Enjoy our curated collection of examples and solutions. Use these patterns to build your own robust and scalable applications.
TypeScript
3,556
star
21

hazel

Lightweight update server for Electron apps
JavaScript
2,896
star
22

next-plugins

Official Next.js plugins
2,677
star
23

next-app-router-playground

https://app-router.vercel.app/
TypeScript
2,534
star
24

geist-font

2,250
star
25

virtual-event-starter-kit

Open source demo that Next.js developers can clone, deploy, and fully customize for events.
TypeScript
2,148
star
26

async-retry

Retrying made simple, easy and async
JavaScript
1,808
star
27

react-tweet

Embed tweets in your React application.
TypeScript
1,615
star
28

little-date

A friendly formatter to make date ranges small & sweet
TypeScript
1,553
star
29

nft

Node.js dependency tracing utility
JavaScript
1,287
star
30

arg

Simple argument parsing
JavaScript
1,222
star
31

style-guide

Vercel's engineering style guide
JavaScript
1,209
star
32

avatar

💎 Beautiful avatars as a microservice
TypeScript
1,155
star
33

nextjs-postgres-nextauth-tailwindcss-template

Admin dashboard template.
TypeScript
1,108
star
34

modelfusion

The TypeScript library for building AI applications.
TypeScript
1,084
star
35

next-react-server-components

Demo repository for Next.js + React Server Components
JavaScript
985
star
36

nextjs-postgres-auth-starter

Next.js + Tailwind + Typescript + Drizzle + NextAuth + PostgreSQL starter template.
TypeScript
915
star
37

nextgram

A sample Next.js app showing dynamic routing with modals as a route.
TypeScript
867
star
38

edge-runtime

Developing, testing, and defining the runtime Web APIs for Edge infrastructure.
TypeScript
790
star
39

on-demand-isr

TypeScript
762
star
40

server-components-notes-demo

Experimental demo of React Server Components with Next.js. Deployed serverlessly on Vercel.
TypeScript
734
star
41

micro-dev

The development environment for `micro`
JavaScript
705
star
42

nextjs-portfolio-starter

Easily create a portfolio with Next.js and Markdown.
JavaScript
669
star
43

async-sema

Semaphore using `async` and `await`
TypeScript
631
star
44

static-fun

A fun demo for wildcard domains
TypeScript
629
star
45

hyperpower

Hyper particle effects extension
JavaScript
623
star
46

react-keyframes

Create frame-based animations in React
TypeScript
617
star
47

title

A service for capitalizing your title properly
JavaScript
579
star
48

fetch

Opinionated `fetch` (with retrying and DNS caching) optimized for use with Node.js
JavaScript
568
star
49

serve-handler

The foundation of `serve`
JavaScript
564
star
50

vrs

A serverless virtual reality e-commerce experience powered by Vercel
TypeScript
517
star
51

storage

Vercel Postgres, KV, Blob, and Edge Config
TypeScript
506
star
52

fun

ƒun - Local serverless function λ development runtime
TypeScript
480
star
53

swr-site

The official website for SWR.
MDX
479
star
54

mongodb-starter

A developer directory built on Next.js and MongoDB Atlas, deployed on Vercel with the Vercel + MongoDB integration.
TypeScript
470
star
55

hyper-site

The official website for the Hyper terminal
JavaScript
435
star
56

spr-landing

Serverless Pre-Rendering Landing Page
CSS
434
star
57

pkg-fetch

A utility to fetch or build patched Node binaries used by `pkg` to generate executables. This repo hosts prebuilt binaries in Releases.
TypeScript
428
star
58

analytics

Privacy-friendly, real-time traffic insights
TypeScript
421
star
59

sveltekit-commerce

SvelteKit Commerce
Svelte
386
star
60

reactions

Next.js Incremental Static Regeneration Demo
JavaScript
309
star
61

email-prompt

CLI email prompt with autocompletion and built-in validation
JavaScript
274
star
62

uid-promise

Creates a cryptographically strong UID
TypeScript
252
star
63

fetch-retry

Wrapper around `fetch` with sensible retrying defaults
JavaScript
221
star
64

git-hooks

No nonsense Git hook management
JavaScript
202
star
65

zsh-theme

Yet another zsh theme
179
star
66

remote-cache

The Vercel Remote Cache SDK
TypeScript
174
star
67

cosmosdb-server

A Cosmos DB server implementation for testing your applications locally.
TypeScript
170
star
68

react-transition-progress

Show a progress bar while React Transitions run
TypeScript
162
star
69

update-check

Minimalistic update notifications for command line interfaces
JavaScript
159
star
70

test-listen

Quick ephemeral URLs for your tests
JavaScript
153
star
71

terraform-provider-vercel

Terraform Vercel Provider
Go
142
star
72

install-node

Simple one-liner shell script that installs official Node.js binaries
Shell
141
star
73

title-site

A website for capitalizing your titles
JavaScript
126
star
74

community

Welcome to the Vercel Community. Discuss feature requests, ask questions, and connect with others in the community.
111
star
75

preview-mode-demo

This demo showcases Next.js' next-gen Static Site Generation (SSG) support.
TypeScript
110
star
76

nextjs-discord-bot

Discord bot for the official Next.js Discord
TypeScript
108
star
77

beginner-sveltekit

The complete course to start your journey building Svelte applications.
JavaScript
101
star
78

commerce-framework

TypeScript
99
star
79

err-sh

Microservice that forwards you to error messages
JavaScript
97
star
80

webpack-asset-relocator-loader

Used in ncc while emitting and relocating any asset references
JavaScript
96
star
81

hyperyellow

Example theme for hyperterm
JavaScript
87
star
82

schemas

All schemas used for validation that are shared between our projects
JavaScript
80
star
83

opentelemetry-collector-dev-setup

Shell
72
star
84

nuxt3-kitchen-sink

An example template showing all Nuxt 3 features on Vercel.
Vue
67
star
85

next-codemod

codemod transformations to help upgrade Next.js codebases
JavaScript
63
star
86

speed-insights

Vercel Speed Insights package
TypeScript
56
star
87

ai-sdk-rag-starter

TypeScript
55
star
88

wait-for

Small utility that waits for a file to exist and optionally have some permissions set.
C
46
star
89

async-listen

Promisify server.listen for your HTTP/HTTPS/TCP server.
TypeScript
45
star
90

tracing-js

An implementation of Opentracing API for honeycomb.io
TypeScript
43
star
91

example-integration

TypeScript
42
star
92

dns-cached-resolve

Caching DNS resolver
TypeScript
41
star
93

fetch-cached-dns

A decorator on top of `fetch` that caches the DNS query
JavaScript
36
star
94

resolve-node

API endpoint to resolve an arbitrary Node.js version with semver support
JavaScript
30
star
95

remark-capitalize

Transform all markdown titles with title.sh
JavaScript
29
star
96

cra-to-next

An example of migrating Create React App to Next.js.
JavaScript
29
star
97

otel

OTEL tracing for Vercel
TypeScript
27
star
98

stripe-integration

A Vercel deploy integration to automatically set up your Stripe API keys and webhook secrets.
TypeScript
25
star
99

rcurl

`curl --resolve` helper script
Shell
23
star
100

gatsby-plugin-vercel

Track Core Web Vitals in Gatsby projects with Vercel Analytics.
JavaScript
21
star