Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ffe5a1c
Initial work, copied from the Shopify provider
patrys Apr 14, 2021
b5e21a5
Added basis setup and type generation for the products queries
royderks Apr 16, 2021
1e946c8
refactor: adjust the types
zaiste Apr 19, 2021
89f6c1c
task: relax the Node.js constraint
zaiste Apr 19, 2021
5402af4
fix: page/product properties
zaiste Apr 19, 2021
de1f325
disable unknown fields
zaiste Apr 19, 2021
0124368
mention Saleor in the README
zaiste Apr 19, 2021
740192a
setup debugging for Next.js
zaiste Apr 19, 2021
bbbe270
Check nextjs-commerce bug if no images are added for a product
royderks Apr 20, 2021
65df803
fix: client/server pecularities for env visibility
zaiste Apr 20, 2021
a4cc162
re: make search work with Saleor API (WIP)
zaiste Apr 20, 2021
5283b01
task: update deps
zaiste Apr 20, 2021
ef10084
task: move to Webpack 5.x
zaiste Apr 20, 2021
1944574
saleor: initial cart integration
zaiste Apr 26, 2021
7a37bc8
update deps
zaiste Apr 26, 2021
34ab15b
saleor: shall the cart appear!
zaiste Apr 27, 2021
2c097b0
task: remove deprecated packages
zaiste Apr 27, 2021
7d80fad
saleor: adding/removing from the cart
zaiste Apr 28, 2021
7524f5a
saleor: preliminary signup process
zaiste Apr 28, 2021
a8678bd
saleor: fix the prices in the cart
zaiste Apr 29, 2021
31ae618
update deps
zaiste Apr 29, 2021
c26c688
update deps
zaiste May 7, 2021
e3a9fd6
Added the options for a variant to the product page
royderks Apr 20, 2021
f7796b9
Mapped options to variants
royderks Apr 29, 2021
85d203e
Mapped options to variants
royderks Apr 29, 2021
e98a9f4
saleor: refine the auth process
zaiste May 11, 2021
3873b48
saleor: remove unused code
zaiste May 11, 2021
8e29a0b
saleor: handle customer find via refresh
zaiste May 11, 2021
e0ee258
saleor: update deps
zaiste May 11, 2021
3b559e9
saleor: fix the session handling
zaiste May 12, 2021
42ae126
saleor: fix the variants
zaiste May 12, 2021
2fe2c71
saleor: simplify the naming for GraphQL statements
zaiste May 12, 2021
f4b66f2
saleor: fix the type for collection
zaiste May 12, 2021
9ca6c38
saleor: arrange the error codes
zaiste May 12, 2021
f5ec8e1
saleor: integrate collections
zaiste May 13, 2021
51e2dae
saleor: fix product sorting
zaiste May 13, 2021
efdf4d9
saleor: set cookie location
zaiste May 13, 2021
96f79e3
saleor: update the schema
zaiste May 13, 2021
3e72dfc
saleor: attach checkout to customer
zaiste May 14, 2021
df3d85f
saleor: fix the checkout flow
zaiste May 14, 2021
f530704
saleor: unify GraphQL naming approach
zaiste May 14, 2021
d8eb43a
task: update deps
zaiste May 18, 2021
bf68f6a
Add the env variables for saleor to the template
royderks May 18, 2021
4a652a9
task: prettier
zaiste May 18, 2021
02cf125
saleor: stub API for build/typescript compilation
zaiste May 18, 2021
5f41b6a
task: temporarily disable for the `build`
zaiste May 18, 2021
1959647
saleor: refactor GraphQL queries
zaiste May 20, 2021
0d0b3fc
saleor: adjust the config
zaiste May 20, 2021
989993c
task: update dependencies
zaiste May 20, 2021
5b08545
revert: Next.js to `10.0.9`
zaiste May 20, 2021
ae3ff8e
saleor: fix the checkout fetch query
zaiste May 20, 2021
dfd254c
task: update dependencies
zaiste May 31, 2021
79e916f
saleor: adapt for displaying featured products
zaiste Jun 1, 2021
3399228
saleor: update the provider structure
zaiste Jun 4, 2021
0cf76d9
saleor: make the home page representable
zaiste Jun 5, 2021
397ffc1
feature/cart: display the variant name (cond)
zaiste Jun 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN=

NEXT_PUBLIC_SWELL_STORE_ID=
NEXT_PUBLIC_SWELL_PUBLIC_KEY=

NEXT_PUBLIC_SALEOR_API_URL=
NEXT_PUBLIC_SALEOR_CHANNEL=
10 changes: 9 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"useTabs": false
"useTabs": false,
"overrides": [
{
"files": ["framework/saleor/**/*"],
"options": {
"printWidth": 120
}
}
]
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Demo live at: [demo.vercel.store](https://demo.vercel.store/)
- Swell Demo: https://swell.vercel.store/
- BigCommerce Demo: https://bigcommerce.vercel.store/
- Vendure Demo: https://vendure.vercel.store
- Saleor Demo: https://saleor.vercel.store/

## Features

Expand All @@ -26,7 +27,7 @@ Demo live at: [demo.vercel.store](https://demo.vercel.store/)

## Integrations

Next.js Commerce integrates out-of-the-box with BigCommerce and Shopify. We plan to support all major ecommerce backends.
Next.js Commerce integrates out-of-the-box with BigCommerce, Shopify and Saleor. We plan to support all major ecommerce backends.

## Considerations

Expand Down
1 change: 0 additions & 1 deletion assets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,3 @@ a {
opacity: 1;
}
}

2 changes: 1 addition & 1 deletion assets/components.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.fit {
min-height: calc(100vh - 88px);
}
}
27 changes: 27 additions & 0 deletions codegen.bigcommerce.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"schema": {
"https://buybutton.store/graphql": {
"headers": {
"Authorization": "Bearer xzy"
}
}
},
"documents": [
{
"./framework/bigcommerce/api/**/*.ts": {
"noRequire": true
}
}
],
"generates": {
"./framework/bigcommerce/schema.d.ts": {
"plugins": ["typescript", "typescript-operations"]
},
"./framework/bigcommerce/schema.graphql": {
"plugins": ["schema-ast"]
}
},
"hooks": {
"afterAllFileWrite": ["prettier --write"]
}
}
22 changes: 14 additions & 8 deletions codegen.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
{
"schema": {
"https://buybutton.store/graphql": {
"headers": {
"Authorization": "Bearer xzy"
}
}
"https://master.staging.saleor.cloud/graphql/": {}
},
"documents": [
{
"./framework/bigcommerce/api/**/*.ts": {
"./framework/saleor/utils/queries/get-all-products-query.ts": {
"noRequire": true
}
},
{
"./framework/saleor/utils/queries/get-all-products-paths-query.ts": {
"noRequire": true
}
},
{
"./framework/saleor/utils/queries/get-products.ts": {
"noRequire": true
}
}
],
"generates": {
"./framework/bigcommerce/schema.d.ts": {
"./framework/saleor/schema.d.ts": {
"plugins": ["typescript", "typescript-operations"]
},
"./framework/bigcommerce/schema.graphql": {
"./framework/saleor/schema.graphql": {
"plugins": ["schema-ast"]
}
},
Expand Down
3 changes: 2 additions & 1 deletion commerce.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"features": {
"wishlist": true
"wishlist": false,
"customCheckout": false
}
}
8 changes: 6 additions & 2 deletions components/cart/CartItem/CartItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,14 @@ const CartItem = ({
<div className="flex-1 flex flex-col text-base">
<Link href={`/product/${item.path}`}>
<span
className="font-bold text-lg cursor-pointer leading-6"
onClick={() => closeSidebarIfPresent()}
>
{item.name}
<div
className="font-bold text-lg cursor-pointer leading-6"
>
{item.name}
</div>
{item.variant ? <span> {item.variant.name}</span> : ""}
</span>
</Link>
{options && options.length > 0 ? (
Expand Down
9 changes: 2 additions & 7 deletions components/common/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,8 @@ const Layout: FC<Props> = ({
children,
pageProps: { categories = [], ...pageProps },
}) => {
const {
displaySidebar,
displayModal,
closeSidebar,
closeModal,
modalView,
} = useUI()
const { displaySidebar, displayModal, closeSidebar, closeModal, modalView } =
useUI()
const { acceptedCookies, onAcceptCookies } = useAcceptCookies()
const { locale = 'en-US' } = useRouter()

Expand Down
4 changes: 2 additions & 2 deletions components/product/ProductCard/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Props {
className?: string
product: Product
variant?: 'slim' | 'simple'
imgProps?: Omit<ImageProps, 'src'>
imgProps?: Omit<any, 'src'>
}

const placeholderImg = '/product-img-placeholder.svg'
Expand Down Expand Up @@ -38,7 +38,7 @@ const ProductCard: FC<Props> = ({
alt={product.name || 'Product Image'}
height={320}
width={320}
layout="fixed"
layout="fixed"
{...imgProps}
/>
)}
Expand Down
8 changes: 5 additions & 3 deletions components/product/ProductView/ProductView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ const ProductView: FC<Props> = ({ product }) => {

useEffect(() => {
// Selects the default option
product.variants[0].options?.forEach((v) => {
const options = product.variants[0].options || []
options.forEach((v) => {
setChoices((choices) => ({
...choices,
[v.displayName.toLowerCase()]: v.values[0].label.toLowerCase(),
[v.displayName.toLowerCase()]: v.values[0]?.label.toLowerCase(),
}))
})
}, [])
Expand Down Expand Up @@ -126,7 +127,8 @@ const ProductView: FC<Props> = ({ product }) => {
setChoices((choices) => {
return {
...choices,
[opt.displayName.toLowerCase()]: v.label.toLowerCase(),
[opt.displayName.toLowerCase()]:
v.label.toLowerCase(),
}
})
}}
Expand Down
5 changes: 2 additions & 3 deletions components/ui/Container/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ const Container: FC<Props> = ({ children, className, el = 'div', clean }) => {
'mx-auto max-w-8xl px-6': !clean,
})

let Component: React.ComponentType<
React.HTMLAttributes<HTMLDivElement>
> = el as any
let Component: React.ComponentType<React.HTMLAttributes<HTMLDivElement>> =
el as any

return <Component className={rootClassName}>{children}</Component>
}
Expand Down
4 changes: 3 additions & 1 deletion framework/commerce/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const fs = require('fs')
const merge = require('deepmerge')
const prettier = require('prettier')

const PROVIDERS = ['bigcommerce', 'shopify', 'swell', 'vendure']
const PROVIDERS = ['bigcommerce', 'shopify', 'swell', 'vendure', 'saleor']

function getProviderName() {
return (
Expand All @@ -18,6 +18,8 @@ function getProviderName() {
? 'shopify'
: process.env.NEXT_PUBLIC_SWELL_STORE_ID
? 'swell'
: process.env.NEXT_PUBLIC_SALEOR_API_URL
? 'saleor'
: null)
)
}
Expand Down
61 changes: 33 additions & 28 deletions framework/commerce/new-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
A commerce provider is a headless e-commerce platform that integrates with the [Commerce Framework](./README.md). Right now we have the following providers:

- BigCommerce ([framework/bigcommerce](../bigcommerce))
- Saleor ([framework/saleor](../saleor))
- Shopify ([framework/shopify](../shopify))

Adding a commerce provider means adding a new folder in `framework` with a folder structure like the next one:
Expand Down Expand Up @@ -156,24 +157,26 @@ export const handler: SWRHook<
const data = cartId ? await fetch(options) : null
return data && normalizeCart(data)
},
useHook: ({ useData }) => (input) => {
const response = useData({
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
})
useHook:
({ useData }) =>
(input) => {
const response = useData({
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
})

return useMemo(
() =>
Object.create(response, {
isEmpty: {
get() {
return (response.data?.lineItems.length ?? 0) <= 0
return useMemo(
() =>
Object.create(response, {
isEmpty: {
get() {
return (response.data?.lineItems.length ?? 0) <= 0
},
enumerable: true,
},
enumerable: true,
},
}),
[response]
)
},
}),
[response]
)
},
}
```

Expand Down Expand Up @@ -217,18 +220,20 @@ export const handler: MutationHook<Cart, {}, CartItemBody> = {

return normalizeCart(data)
},
useHook: ({ fetch }) => () => {
const { mutate } = useCart()

return useCallback(
async function addItem(input) {
const data = await fetch({ input })
await mutate(data, false)
return data
},
[fetch, mutate]
)
},
useHook:
({ fetch }) =>
() => {
const { mutate } = useCart()

return useCallback(
async function addItem(input) {
const data = await fetch({ input })
await mutate(data, false)
return data
},
[fetch, mutate]
)
},
}
```

Expand Down
22 changes: 10 additions & 12 deletions framework/commerce/utils/define-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ type InferValue<Prop extends PropertyKey, Desc> = Desc extends {
? Record<Prop, T>
: never

type DefineProperty<
Prop extends PropertyKey,
Desc extends PropertyDescriptor
> = Desc extends { writable: any; set(val: any): any }
? never
: Desc extends { writable: any; get(): any }
? never
: Desc extends { writable: false }
? Readonly<InferValue<Prop, Desc>>
: Desc extends { writable: true }
? InferValue<Prop, Desc>
: Readonly<InferValue<Prop, Desc>>
type DefineProperty<Prop extends PropertyKey, Desc extends PropertyDescriptor> =
Desc extends { writable: any; set(val: any): any }
? never
: Desc extends { writable: any; get(): any }
? never
: Desc extends { writable: false }
? Readonly<InferValue<Prop, Desc>>
: Desc extends { writable: true }
? InferValue<Prop, Desc>
: Readonly<InferValue<Prop, Desc>>

export default function defineProperty<
Obj extends object,
Expand Down
4 changes: 4 additions & 0 deletions framework/saleor/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
COMMERCE_PROVIDER=saleor

NEXT_SALEOR_API_URL=
NEXT_SALEOR_CHANNEL=
19 changes: 19 additions & 0 deletions framework/saleor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Saleor Provider

**Demo:** TBD

Before getting starter, a [Saleor](https://saleor.io/) account and store is required before using the provider.

Next, copy the `.env.template` file in this directory to `.env.local` in the main directory (which will be ignored by Git):

```bash
cp framework/saleor/.env.template .env.local
```

Then, set the environment variables in `.env.local` to match the ones from your store.

## Contribute

Our commitment to Open Source can be found [here](https://vercel.com/oss).

If you find an issue with the provider or want a new feature, feel free to open a PR or [create a new issue](https://github.com/vercel/commerce/issues).
1 change: 1 addition & 0 deletions framework/saleor/api/cart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function () {}
1 change: 1 addition & 0 deletions framework/saleor/api/catalog/products.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function () {}
1 change: 1 addition & 0 deletions framework/saleor/api/checkout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function () {}
1 change: 1 addition & 0 deletions framework/saleor/api/customers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function () {}
1 change: 1 addition & 0 deletions framework/saleor/api/customers/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function () {}
1 change: 1 addition & 0 deletions framework/saleor/api/customers/logout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function () {}
1 change: 1 addition & 0 deletions framework/saleor/api/customers/signup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function () {}
1 change: 1 addition & 0 deletions framework/saleor/api/endpoints/cart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function (_commerce: any) {}
1 change: 1 addition & 0 deletions framework/saleor/api/endpoints/catalog/products.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function (_commerce: any) {}
Loading