Live demo: https://foxy-contentful-nextjs.vercel.app/
Step-by-step guide: Build a JAMstack Ecommerce Website with Next.js, Contentful, and Foxy
- Next.js - Front-end framework
- Contentful - Headless CMS
- Foxy - Shopping cart
- Vercel - Deployment
- Tailwind CSS - CSS framework
- GraphQL - Query language for Contentful API
-
Sign up or log in your Foxy admin account
-
Create a new store or use an existing one. Other settings are optional. The key thing is to have your own Foxy store subdomain.
-
Sign up or log in Contentful, and create a new empty space from the dashboard
-
From the newly created space, go to Content model and add a new content type: give it the Name
Product
, the Api Identifier should beproduct
-
Add these fields and configure all as required fields:
name
- Text field (type short text)slug
- Text field. You can optionally go to the settings of this field, and under Appearance, select Slug to display it as a slug of thename
field.price
- Number field (type Decimal)image
- Media field (type one file)inventory
- Number field (type Integer)description
- Rich text fieldfeatured
- Boolean field
-
Head to the Content tab, add a few products and publish
From your Contentful space, go to Settings > API keys. There will be an example Content delivery / preview token - you can use these API keys or create a new key.
-
CONTENTFUL_SPACE_ID
should be the Space ID field of your API Key -
CONTENTFUL_ACCESS_TOKEN
should be the Content Delivery API - access token field of your API key -
NEXT_PUBLIC_FOXY_SUBDOMAIN
should be the Foxy store subdomain, which can be found in the Foxy admin Dashboard. For exmaple, if your store domain isfoxy-demo.foxycart.com
, the subdomain would befoxy-demo
-
FOXY_STORE_SECRET
is required only if you want to enable Foxy HMAC cart validation. To get this variable value, go to Advanced Settings in the Foxy admin. Look for the "store secret" setting, click the "Show" button, and copy the value in the text box. Also, you need to check the "would you like to enable cart validation?" option in the same section
- Clone this repo:
git clone https://github.com/lrnxie/foxy-contentful-nextjs
- Copy the
.env.example
file to.env.local
, and set the variables - Make your changes
- Push it to GitHub/GitLab/Bitbucket and import to Vercel.
Important: When you import your project on Vercel, make sure to click on Environment Variables and set them to match your .env.local
file.