Git Product home page Git Product logo

jamstack-ecommerce's Introduction

Jamstack ECommerce Next

Jamstack ECommerce Next provides a way to quickly get up and running with a fully configurable ECommerce site using Next.js.

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.

Home

Live preview

Click here to see a live preview.

Other Jamstack ECommerce pages

Category view

Category view

Item view

Item view

Cart view

Cart view

Admin panel

Admin panel

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
$ npm run dev

# or to build

$ npm run build

Deploy to Vercel

Use the Vercel CLI

vercel

Deploy to AWS

npx serverless

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 - public/logo.png
Button, ListItem, etc.. - components
Form components - components/formComponents
Context (state) - context/mainContext.js
Pages (admin, cart, checkout, index) - pages
Templates (category view, single item view, inventory views) - 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 utils/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 to 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 pages/admin.js with sign up, sign, in, sign out, and confirm sign in methods.

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

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

Roadmap

  • Full product and category search
  • Auto dropdown navigation for large number of categories
  • Ability to add more / more configurable metadata to item details
  • Themeing + dark mode
  • Optional user account / profiles out of the box
  • Make Admin Panel responsive
  • Have an idea or a request? Submit an issue or a pull request!

Other considerations

Server-side processing of payments

To see an example of how to process payments server-side with stripe, check out the Lambda function in the snippets folder.

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.

jamstack-ecommerce's People

Contributors

dabit3 avatar petermekhaeil avatar stav avatar swyxio avatar thorsten-stripe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jamstack-ecommerce's Issues

Great Site, Can Stripe be replaced? and with what?

Hi, how are you?
I was interested in using this site as a theme for my own little project known as Sepochi Co but saw that stripe is required and that turned me off.
I don't refuse, stripe is a great payment processing platform but i live in an unsupported country and Stripe Atlas is too pricy for me. What other alternative exist that are world wide and how can i integrate them and remove strip.
Kindly help me.

Bump this up to Next 14?

This project seems discontinued. It's a pity. People still need a super simple and clean eCommerce site without all the burden of a backend.

Anyone who bumped this up to Next 14? Anyone built i18n for this? Thanks.

Inventory Management w. Stripe Work Around: Multiple Images Per Product

As a shop owner (non-technical user) I want to...

...add multiple images to a single product; for example, couch A comes in multiple colors, the website should display a picture for each w/o treating each color-variant as it's own product.

NOTES:

  1. This is a shortcoming with the stripe inventory management CMS.
  2. You can do this via a call to the Stripe API, but (a) the inventory management dashboard still only shows one image and (b) this issue was created assuming the shop owner is a non-technical user

Does not appear to be Gatsby project

Hi Nader,
I too have had this issue where the Gatsby project JAMstack-ecommerce appears to be a React project.
I loaded as per your specifications
https://dev.to/aws/building-a-serverless-jamstack-ecommerce-store-with-gatsby-aws-303f
Tried gatsby develop and got failure.
Bit of muting around and then Trying npm run it started on Localhost:3000

On closer inspection it appears to not be a Gatsby project?
Do you have the original somewhere else maybe and it got moved?
Like Nabuko I too would like to try this out Gatsby Amplify etc
This is the link to the repository from the page that I loaded

https://github.com/jamstack-cms/jamstack-ecommerce

Really hope this is able to be corrected as really would like to Try a Gatsby AWS Stripe project
Thanks in advance Mark

[BUG] Demo Site โ€“ Remove item from cart

Steps to Reproduce

  1. Add a single item to the cart multiple times
  2. View cart
  3. Remove 1 of the duplicate items

What's Happening

All duplicate items are removed

What's expected

Only a single duplicate item should be removed


Looks like it's due to the fact that removal is based on id and they're all the same ... Bunch of different ways to go about fixing it, just wanted to mention it exists. Nice work on this, btw. Really digging the simplicity of the store design.

Don't find gatsby

Hello Nader and everyone,

Maybe i'm too dumb, but I follow all the instructions on git and on https://dev.to/aws/building-a-serverless-jamstack-ecommerce-store-with-gatsby-aws-303f, and I dont't find anything about gatsby.

I clone, go to the good directory, npm install, and then I want to do Gatsby develop, and that don't work :'(

npm run dev work perfectly, but really want to have the same things as Nader Dabit

I try npm install -g gatsby-cli, and creata a new project but i cant clone yours in it :'(

So if you can give me some advice, i take it.

Good day to you.
Nab

Dockerise this application

Hi team,

I would like to contribute to this project by dockerising this application so that anyone can run this application on their local system just with a single command. I will also update the readme so that anyone can get started with this project easily.

Please assign this issue to me and I will get started with it right away.

Thanks

I can't log in to admin or create an account

I followed all the steps in this tutorial:
https://dev.to/aws/building-a-serverless-jamstack-ecommerce-store-with-gatsby-aws-303f

But when I go to the Admins panel in the bottom right navigation, the Sign Up/ Sign In buttons don't do anything.

I was trying to create an admin account and got the email with a verification code, but when I put the code in, the button didn't do anything.

Now neither buttons work and I'm not sure why.

I don't know if this will help but here is a screenshot of the console:

console-screenshot

Any ideas?

As far as disorganized, this is king (of disorder)

I honestly, have not seen a more disorganised piece of work.

I respect the thought that was pulling it together, but fundametally, you owe it to yourself to organise your code in a fashion that succeeds you as the developer.

As a mode to train, I would advise against using this, but this is a learning opportuntity for any developer out there.

Your code is your thoughts. Your thoughts are the base of which other developers build. Shit code leads to shit builds, and this is perfect in example.

I need to strip it all the way down to make it useful.

Note, I'm not being a pain for no reason, but anyone who organises their folders like this project deserves a beating

stripe is not processing charges

I'm starting to understand how Gatsby and still fail to understand how this completely work.

My main goal is to upload it to netlify, use netlify login to access the admin site and use netlify cms to edit or add items.
Then I would like to process every payment and create invoices with automatic mails with stripe.

First things first, I want to proccess the payment for a simple sofa and I'm having a little trouble with it.

When testing the website after gatsby develop, I don't see the charge at stripe dot com.
I'm using the testing publishable key.

In stripe the only thing I see is an API call to:
/v1/payment_methods

2020-08-31 223025

But I can't see the charge in payments, nor the item details in the call...
Is it necesary to use the lambda.js?
And how exactly could I run lambda.js? is it a node.js code? do I need to upload it as a micro-service elsewhere? I figure I should add the secret API key there but is it really necessary?

For now I'm just testing everything locally.

Thank you so much, this is looking too good. Any help or advice will be much appreciated.

Can stripe be replaced with something like paypal?

Hi, how are you?
I'm interested in using this theme sadly both me and my client live in stripe unsupported country. And Stripe Atlas is an additional expense that my client isn't interested in. So is there way to replace stripe with Paypal? If so can you help me do it or pay you to do it for me?

Navbar links rise a problem

When user is not on Homepage /, a problem occur in the navbar links. All links link to a misplaced file.

  1. Navigate to the New arrivals page
  2. Now click on another navbar link, such as Sofas
  3. A 404 page is showen, /new-arrivals/sofas Not Found

Why the problem occur ?

In the following JavaScript code,

<Link to={l.link} key={i}>

link values are missing a / prefix. And it render as:

<a href="sofas>

How can we resolve the issue ?

Prefix all links with a /.

<Link to={`/${l.link}`} key={i}>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.