• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 4 years ago

Reviews

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

Repository Details

JAMstack ECommerce Professional (Beta)

JAMstack ECommerce Professional provides a way to quickly get up and running with a fully configurable JAMstack E Commerce site.

Out of the box, the site uses completely static data coming from a provider at providers/inventoryProvider.js. You can update this provider to fetch data from any real API by changing the call in the getInventory function.

This project is still in Beta.

Getting started

  1. Clone the project
$ git clone https://github.com/jamstack-cms/jamstack-ecommerce.git
  1. Install the dependencies:
$ yarn

# or

$ npm install
  1. Run the project
$ gatsby develop

# or to build

$ gatsby build

About the project

Tailwind

This project is styled using Tailwind. To learn more how this works, check out the Tailwind documentation here.

Components

The main files, components, and images you may want to change / modify are:

Logo - src/images/logo.png
Buttons, Nav, Header - src/components
Form components - src/components/formComponents
Context (state) - src/context/mainContext.js
Pages (admin, cart, checkout, index) - src/pages
Templates (category view, single item view, inventory views) - src/templates

How it works

As it is set up, inventory is fetched from a local hard coded array of inventory items. This can easily be configured to instead be fetched from a remote source like Shopify or another CMS or data source by changing the inventory provider.

Configuring inventory provider

Update providers/inventoryProvider.js with your own inventory provider.

Download images at build time

If you change the provider to fetch images from a remote source, you may choose to also download the images locally at build time to improve performance. Here is an example of some code that should work for this use case:

import fs from 'fs'
import axios from 'axios'
import path from 'path'

function getImageKey(url) {
  const split = url.split('/')
  const key = split[split.length - 1]
  const keyItems = key.split('?')
  const imageKey = keyItems[0]
  return imageKey
}

function getPathName(url, pathName = 'downloads') {
  let reqPath = path.join(__dirname, '..')
  let key = getImageKey(url)
  key = key.replace(/%/g, "")
  const rawPath = `${reqPath}/public/${pathName}/${key}`
  return rawPath
}

async function downloadImage (url) {
  return new Promise(async (resolve, reject) => {
    const path = getPathName(url)
    const writer = fs.createWriteStream(path)
    const response = await axios({
      url,
      method: 'GET',
      responseType: 'stream'
    })
    response.data.pipe(writer)
    writer.on('finish', resolve)
    writer.on('error', reject)
  })
}

export default downloadImage

You can use this function in gatsby-node.esm.js, map over the inventory data after fetching and replace the image paths with a reference to the location of the downloaded images, probably would look something like this:

await Promise.all(
  inventory.map(async (item, index) => {
    try {
      const relativeUrl = `../downloads/${item.image}`
      if (!fs.existsSync(`${__dirname}/public/downloads/${item.image}`)) {
        await downloadImage(image)
      }
      inventory[index].image = relativeUrl
    } catch (err) {
      console.log('error downloading image: ', err)
    }
  })
)

Updating with Auth / Admin panel

  1. Update src/pages/admin.js with sign up, sign, in, sign out, and confirm sign in methods.

  2. Update src/templates/ViewInventory.js with methods to interact with the actual inventory API.

  3. Update src/components/formComponents/AddInventory.js with methods to add item to actual inventory API.

Roadmap for V1

  • Add ability to specify quantities in cart
  • Auto dropdown navigation for large number of categories
  • Ability to add more / more configurable metadata to item details
  • Themeing + dark mode
  • Better image support out of the box
  • Optional user account / profiles out of the box
  • Have an idea or a request? Submit an issue or a pull request!

Other considerations

Server-side processing of payments

Alongside Gatsby, we deploy a function called /api, which can be used to submit a payment.

The original codebase doesn't yet make the request to process the payment, but it should be easy to add with fetch.

Also, consider verifying totals by passing in an array of IDs into the function, calculating the total on the server, then comparing the totals to check and make sure they match.

More Repositories

1

slackin

Public Slack organizations made easy
JavaScript
6,505
star
2

wifi-password

Get the password of the wifi you're on (bash)
Shell
4,423
star
3

blog

MDX
1,208
star
4

spot

Tiny file search utility (bash)
Shell
927
star
5

next-ai-news

TypeScript
811
star
6

chat-example

HTML
796
star
7

weplay

Collaborative gameboy emulation powered 100% by JavaScript
JavaScript
605
star
8

how-is-this-not-illegal

A demo of using RSC and Vercel Postgres, legally
JavaScript
582
star
9

clif

Dead easy terminal GIFs, from the terminal.
JavaScript
448
star
10

node.websocket.js

WebSocket-compatible realtime HTTP server implemented with Node.JS
JavaScript
265
star
11

react-postgres-components

An experiment on deploying remote functions that run inside Postgres using v8
TypeScript
176
star
12

wingpt

An AI chatbot in Win95 style
TypeScript
166
star
13

node.dbslayer.js

DBSlayer (MySQL) support for Node.JS
JavaScript
150
star
14

wordledge

TypeScript
121
star
15

chrome-spdy-indicator

Chrome Extension to see an indicator of SPDY support in the address bar.
JavaScript
109
star
16

smashingnode

Repository for my book "Smashing Node"
JavaScript
106
star
17

TextboxList

MooTools tokenizer
JavaScript
101
star
18

gameboy

JavaScript
89
star
19

genui-demo

TypeScript
82
star
20

emoji-todo

A simple app to demonstate the ease of fetching and mutating data with Next.js App Router, RSC, and Server Actions.
TypeScript
76
star
21

stream-chart

TypeScript
65
star
22

chromekit

HTML5 window chroming
JavaScript
64
star
23

insights-chrome

IO Insights chrome extension
JavaScript
58
star
24

raycast-web-dev-measure

Raycast extension to quickly measure a site's performance using PageSpeed Insights
Shell
53
star
25

blog-views

JavaScript
49
star
26

pokeless

JavaScript
47
star
27

latency-io

Socket.IO echo example with latency measurement / graphing
JavaScript
42
star
28

jsconf-todo-demo

Demo application using socket.io+nodestream for realtime, express+mongoose for backend
JavaScript
37
star
29

blog-starter

JavaScript
33
star
30

berkshire-deck-demo

JavaScript
30
star
31

next-sqlite

TypeScript
26
star
32

PluginsKit

Plugins repository for open source projects linked to GitHub
PHP
25
star
33

weplay-emulator

runs the emulator that communicates with the weplay io backend
JavaScript
24
star
34

express-trace

Express route/middleware tracer & profiler
JavaScript
21
star
35

s.js

tiny javascript sprintf
JavaScript
20
star
36

jsconfar

CSS
19
star
37

gitfollow

Add a GitHub followers badge to your website!
JavaScript
18
star
38

Cube5

A CSS3 animated 3D Cube layout
15
star
39

phpshortener

PHP URL Shortening encoder/decoder class.
PHP
14
star
40

ray-city

A city animation that fits in a tweet
HTML
14
star
41

APNG

Animated PNG cross-browser utility.
JavaScript
13
star
42

moogets

Guillermo's MooTools plugins.
JavaScript
13
star
43

gox-now

Example of cross-compiling Go on Now and hosting the resulting binaries in the Now CDN
Dockerfile
13
star
44

weplay-web

JavaScript
12
star
45

mongoose-meetup-04-05

Examples used for the presentation
JavaScript
11
star
46

pkg-now

Example of cross-compiling Node.js on Now and hosting the resulting binaries in the Now CDN
Dockerfile
10
star
47

oscon-chat

My oscon presentation chat app
JavaScript
10
star
48

define.js

Tiny Node.js script to pull definitions from Google
JavaScript
9
star
49

project-template-next.js

Next.js template for CodeSandbox Projects
TypeScript
8
star
50

ios6-bugs

Test cases for iOS6 Mobile Safari bugs
JavaScript
7
star
51

weplay-presence

JavaScript
6
star
52

mdx-deck-theme-berkshire

JavaScript
3
star
53

thereallybigone

CSS
3
star
54

brevity

Brevity is an operating system. Itโ€™s easy to use, free, and based on Linuxโ€ and web technologies.
JavaScript
3
star
55

inception.js

2
star
56

router

Fork of reach/router to demonstrate Now CI
JavaScript
2
star
57

belkirk-jekyll-demo

HTML
1
star
58

sample-app

JavaScript
1
star
59

blob-to-image

JavaScript
1
star
60

hi-fregante

HTML
1
star