Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/commercelayer/gatsby-commerce

Commerce Layer + Gatsby Tutorial
https://github.com/commercelayer/gatsby-commerce

commercelayer ecommerce gatsby headless jamstack

Last synced: about 1 month ago
JSON representation

Commerce Layer + Gatsby Tutorial

Awesome Lists containing this project

README

        

# Commerce Layer + Gatsby Tutorial

> How to integrate integrate the [Commerce Layer API](https://commercelayer.io/api/reference/) into your Gatsby application.

## 1. Install Gatsby

```shell
npm install --global gatsby-cli
```

## 2. Create a new site

```shell
gatsby new gatsby-commerce
```

## 3. Install the Commerce Layer Plugin

```shell
npm install gatsby-plugin-commercelayer --save
```

```javascript
# gatsby-config.js
module.exports = {
plugins: ['gatsby-plugin-commercelayer']
}
```

## 4. Create a demo page

Make sure you understand [how it works](https://github.com/commercelayer/static-commerce) and create some demo pages, like the following:

### Category page

```jsx
import React, { Component } from 'react'
import Layout from "../components/layout"
import * as CLayer from 'commercelayer-react'

export default class App extends Component {

render () {
return (






Items


Subtotal


Shipping


Payment


Discount


Taxes


Total











}
/>



Not Available
}
/>




)
}
}
```

### Product page (radio)

```jsx
import React, { Component } from 'react'
import Layout from "../components/layout"
import * as CLayer from 'commercelayer-react'

export default class App extends Component {

render () {
return (














Available in - days with ()
}
/>
Not Available
}
/>



Items


Subtotal


Shipping


Payment


Discount


Taxes


Total











}
/>






)
}
}
```

### Product page (select)

```jsx
import React, { Component } from 'react'
import Layout from "../components/layout"
import * as CLayer from 'commercelayer-react'

export default class App extends Component {

render () {
return (




Available in - days with ()
}
/>
Not Available
}
/>



Items


Subtotal


Shipping


Payment


Discount


Taxes


Total











}
/>






)
}
}
```

## 5. Launch your site

Development:

```shell
gatsby develop
```

Production:

```shell
gatsby build
```