Build an ecommerce website using Snipcart and Contentstack

This example ecommerce website is built using Snipcart’s ecommerce solution and Contentstack. It uses Contentstack to store and deliver the content of the website.

View Demo View Code

Screenshots

Quickstart

Here’s a quick guide on how to create an ecommerce website using Snipcart’s ecommerce solution and Contentstack.

Prerequisites

Note: For this tutorial, we have assumed that you are familiar with Contentstack and Snipcart. If not, then please refer to the docs (Contentstack docs and Snipcart docs) for more details.

Step 1: Create a stack

Log in to your Contentstack account, and create a new stack. This stack will hold all the data, specific to your e-commerce website. Learn more on how to create a stack.

Step 2: Add a publishing environment

To add an environment in Contentstack, navigate to ‘Settings' -> 'Environment', and click on the '+ New Environment’ tab. Provide a suitable name for your environment, say ‘staging’. Specify the base URL (e.g., ‘http://YourDomainName.com’), and select the language (e.g., English - United States). Then, click on 'Save'. Read more about environments.

Step 3: Import content types

A content type is like the structure or blueprint of a page or a section of your web or mobile property. Read more about Content Types.

For this e-commerce website example, four basic content types are required: Header, Footer, Category, and Product. For quick integration, we have already created these content types. You simply need to import them to your stack. You can also create your own content types. Learn how to do this here.

To import the content types, first save the zipped folder of the JSON files given below on your local machine. Extract the files from the folder. Then, go to your stack in Contentstack. The next screen prompts you to either create a new content type or import one into your stack. Click the "Import" link, and select the JSON file saved on your machine.

Here’s a brief overview of all the content types required for this project.

  • Header: This content type lets you add content for the header section of the site. 
  • Footer: The Footer content type enables you to add content for the footer section of your site. 
  • Category: This content type lets you create the various categories of the products of your e-commerce website. The fields of this content type include name and URL.
  • Product: This content type will help you create the product entries of your e-commerce site. The fields include name, URL, category, price, image, and so on.

Download all content types

Now that all the content types are ready, let’s add some content for your e-commerce website.

Step 4: Adding content

Create entries for the Category and Products content type. Add a few entries each for the Category and Products content type. Save and publish these entries. Learn how to create and publish entries.

Create entries for the Header and Footer content types. Using the header content type, add the name and other details of your site. Similarly, add footer content using the footer content type.

With this step, you have created sample data for your e-commerce site. Now, it’s time to setup your Snipcart account and initiate Contentstack app.

Step 5: Setup Snipcart account

If you do not have an account, you can register for one here. When signing up, you can leave the field asking for website URL blank or enter a random value. This can be updated later.

Step 6: Build and configure website

To get your app up and running quickly, we have created a sample e-commerce web app (using Node.JS) for this project. You simple need to download it and change the configuration.

Download code

Note: The website uses the Content Delivery API (which has in-built CDN support) to deliver content to the e-commerce website. Read more about our CDN-enabled content delivery system.

Once you have downloaded the project, add your Snipcart key, Contentstack API Key and Access Token to the project. (Learn how to find your Stack's API Key and Access Token. Read more about Environments.)

The config/all.js file would look something like this:

port: 4000,
  // Contentstack Config
  contentstack: {
    api_key: 'blt1234something',
    access_token: 'blt1234something'
  },
  // Snipcart Key
  snipcart_key: ''

Fire up your terminal (command prompt or similar on Windows), point it to your project location and run the following:

$ npm install
$ npm start

This will initiate your project. However, you will not be able to fully use the checkout process until the project is live on a domain.

Step 7: Go live

You can make the application live by deploying it on any cloud hosting service. In this tutorial, we have used Zeit’s Now. You can download ‘Now’ from here.

Run ‘now' to deploy. Every time you run Now, you get a new deployment!

   $ now

The first time you run Now, it will ask for your email address for verification. Simply click on the email you have received, and you will be logged in automatically.

Once the deployment has started, you will get a link (copied to your clipboard) that you can share immediately with your peers, even before the upload and startup completes!

Step 8: Connecting to Snipcart

The last step is to update your Snipcart settings to point to your new Now site online.

Go to your Snipcart dashboard, click on Account, and then Domains & URLs. Enter your now website URL under Default Website Domain and save your settings.

Your e-commerce site should now be up and running! Try viewing your categories, adding items to your cart, and checking out. While your Snipcart account is in test mode, no purchases will actually be made.

Was this article helpful?
top-arrow