-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f656025
commit f32b924
Showing
13 changed files
with
2,476 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,33 @@ | ||
## nextjs-shopify | ||
# nextjs-shopify | ||
|
||
Check out `/src/storefront/` to see how we hook into Shopify. | ||
## Requirements | ||
|
||
You'll need a Shopify Storefront App to use this example. Follow [this guide](https://help.shopify.com/en/manual/apps/app-types/custom-apps) to do so. | ||
|
||
## Walk Through | ||
|
||
The flow is: | ||
|
||
1. We use `@bsmnt/sdk-gen` to hook into [Shopify's Storefront API](https://shopify.dev/docs/api/storefront) — see this in `/src/storefront/sdk-gen` | ||
2. We use `@bsmnt/storefront-hooks` to create client side hooks that'll help us manage cart state, and more — see this in `/src/storefront/hooks` | ||
3. We use `@bsmnt/drop` to put a drop countdown in fron of our app — see this in `/src/pages/_app` | ||
|
||
## Development | ||
|
||
1. Install yarn (or use whichever package manager you prefer): | ||
|
||
``` | ||
npm install -g yarn | ||
``` | ||
|
||
2. Install the dependencies with: | ||
|
||
``` | ||
yarn | ||
``` | ||
|
||
3. Start developing and watch for code changes: | ||
|
||
``` | ||
yarn dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require('dotenv').config() | ||
|
||
module.exports = { | ||
projects: { | ||
app: { | ||
schema: ['./src/storefront/sdk-gen/generated/graphql.schema.json'], | ||
documents: ['./src/**/*.{graphql,gql}'] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,73 @@ | ||
import { createStorefrontHooks } from "@bsmnt/storefront-hooks"; | ||
import { bsmntSdk } from "../sdk-gen/sdk"; | ||
import { createStorefrontHooks } from '@bsmnt/storefront-hooks' | ||
import { storefront } from '../sdk-gen/sdk' | ||
|
||
export const { | ||
QueryClientProvider, | ||
useCartQuery, | ||
useAddLineItemsToCartMutation, | ||
useOptimisticCartUpdate, | ||
useRemoveLineItemsFromCartMutation, | ||
useUpdateLineItemsInCartMutation, | ||
useUpdateLineItemsInCartMutation | ||
} = createStorefrontHooks({ | ||
cartLocalStorageKey: "example-nextjs-shopify", | ||
cartLocalStorageKey: 'example-nextjs-shopify', | ||
fetchers: { | ||
fetchCart: async (cartId) => { | ||
const { cart } = await bsmntSdk.FetchCart({ id: cartId }); | ||
if (cart === undefined) throw new Error("Request failed"); | ||
return cart; | ||
}, | ||
const { cart } = await storefront.FetchCart({ id: cartId }) | ||
if (cart === undefined) throw new Error('Request failed') | ||
return cart | ||
} | ||
}, | ||
mutators: { | ||
addLineItemsToCart: async (cartId, lines) => { | ||
const { cartLinesAdd } = await bsmntSdk.AddLineItem({ | ||
const { cartLinesAdd } = await storefront.AddLineItem({ | ||
cartId, | ||
lines, | ||
}); | ||
lines | ||
}) | ||
return { | ||
data: cartLinesAdd?.cart, | ||
userErrors: cartLinesAdd?.userErrors, | ||
}; | ||
userErrors: cartLinesAdd?.userErrors | ||
} | ||
}, | ||
createCart: async () => { | ||
const { cartCreate } = await bsmntSdk.CreateCart(); | ||
const { cartCreate } = await storefront.CreateCart() | ||
return { | ||
data: cartCreate?.cart, | ||
userErrors: cartCreate?.userErrors, | ||
}; | ||
userErrors: cartCreate?.userErrors | ||
} | ||
}, | ||
createCartWithLines: async (lines) => { | ||
const { cartCreate } = await bsmntSdk.CreateCartWithLines({ lines }); | ||
const { cartCreate } = await storefront.CreateCartWithLines({ lines }) | ||
return { | ||
data: cartCreate?.cart, | ||
userErrors: cartCreate?.userErrors, | ||
}; | ||
userErrors: cartCreate?.userErrors | ||
} | ||
}, | ||
removeLineItemsFromCart: async (cartId, lineIds) => { | ||
const { cartLinesRemove } = await bsmntSdk.RemoveLineItem({ | ||
const { cartLinesRemove } = await storefront.RemoveLineItem({ | ||
cartId, | ||
lineIds, | ||
}); | ||
lineIds | ||
}) | ||
return { | ||
data: cartLinesRemove?.cart, | ||
userErrors: cartLinesRemove?.userErrors, | ||
}; | ||
userErrors: cartLinesRemove?.userErrors | ||
} | ||
}, | ||
updateLineItemsInCart: async (cartId, lines) => { | ||
const { cartLinesUpdate } = await bsmntSdk.UpdateLineItem({ | ||
const { cartLinesUpdate } = await storefront.UpdateLineItem({ | ||
cartId, | ||
lines: lines.map((l) => ({ | ||
id: l.merchandiseId, | ||
quantity: l.quantity, | ||
attributes: l.attributes, | ||
})), | ||
}); | ||
attributes: l.attributes | ||
})) | ||
}) | ||
return { | ||
data: cartLinesUpdate?.cart, | ||
userErrors: cartLinesUpdate?.userErrors, | ||
}; | ||
}, | ||
userErrors: cartLinesUpdate?.userErrors | ||
} | ||
} | ||
}, | ||
createCartIfNotFound: true, | ||
}); | ||
createCartIfNotFound: true | ||
}) | ||
|
||
export { useProductFormHelper } from './use-product-form-helper' |
Oops, something went wrong.