-
Notifications
You must be signed in to change notification settings - Fork 29
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
Showing
18 changed files
with
10,395 additions
and
0 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 |
---|---|---|
|
@@ -60,3 +60,5 @@ jspm_packages/ | |
|
||
# Lib | ||
lib/ | ||
|
||
.vercel |
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 @@ | ||
.vercel |
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,27 @@ | ||
# Nuxt Shopify Docs | ||
|
||
## Setup | ||
|
||
Install dependencies: | ||
|
||
```bash | ||
yarn install | ||
``` | ||
|
||
## Development | ||
|
||
```bash | ||
yarn dev | ||
``` | ||
|
||
## Static Generation | ||
|
||
This will create the `dist/` directory for publishing to static hosting: | ||
|
||
```bash | ||
yarn generate | ||
``` | ||
|
||
To preview the static generated app, run `yarn start` | ||
|
||
For detailed explanation on how things work, checkout [nuxt/content](https://content.nuxtjs.org) and [@nuxt/content theme docs](https://content.nuxtjs.org/themes-docs). |
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,20 @@ | ||
--- | ||
title: Introduction | ||
description: 'Easy Shopify Buy client integration with Nuxt.js' | ||
position: 1 | ||
category: '' | ||
features: | ||
- Add Shopify client to your Nuxt app in seconds | ||
- Access Shopify SDK with $shopify | ||
- Use isomorphic-unfetch, switches between unfetch & node-fetch for client & server. | ||
- TypeScript support | ||
--- | ||
|
||
<img src="/preview.png" class="light-img" /> | ||
<img src="/preview-dark.png" class="dark-img" /> | ||
|
||
Easy [Shopify Buy](https://shopify.github.io/js-buy-sdk/) client integration with [Nuxt.js](https://nuxtjs.org). | ||
|
||
## Features | ||
|
||
<list :items="features"></list> |
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,95 @@ | ||
--- | ||
title: Setup | ||
description: 'Easy Shopify Buy client integration with Nuxt.js' | ||
position: 2 | ||
category: 'Guide' | ||
--- | ||
|
||
Check the [Nuxt.js documentation](https://nuxtjs.org/api/configuration-modules#the-modules-property) for more information about installing and using modules in Nuxt.js. | ||
|
||
## Setup | ||
|
||
Add `nuxt-shopify` as a dependency to your project: | ||
|
||
<code-group> | ||
<code-block label="Yarn" active> | ||
|
||
```bash | ||
yarn add nuxt-shopify | ||
``` | ||
|
||
</code-block> | ||
<code-block label="NPM"> | ||
|
||
```bash | ||
npm install nuxt-shopify | ||
``` | ||
|
||
</code-block> | ||
</code-group> | ||
|
||
## Storefront access Token | ||
|
||
A Storefront API token is required for this module, follow the shopify guide to get you started: https://shopify.dev/docs/storefront-api/getting-started | ||
|
||
## nuxt.config.js | ||
|
||
```ts | ||
module.exports = { | ||
modules: ['nuxt-shopify'], | ||
|
||
shopify: { | ||
/** | ||
* Your shopify domain | ||
*/ | ||
domain: 'your-shop-name.myshopify.com', | ||
|
||
/** | ||
* Your shopify storefront access token | ||
*/ | ||
storefrontAccessToken: 'your-storefront-access-token', | ||
|
||
/** | ||
* This will be larger than the optimized version, as it will contain all fields that are available in the | ||
* Storefront API. (https://help.shopify.com/en/api/custom-storefronts/storefront-api/reference) | ||
* This should only be used when you need to add custom queries to supplement the JS Buy SDK queries. | ||
*/ | ||
unoptimized: false, | ||
|
||
/** | ||
* Set language to return translated content (optional) | ||
*/ | ||
language: 'ja-JP', | ||
}, | ||
}; | ||
``` | ||
|
||
## TypeScript | ||
|
||
`nuxt-shopify` offers type definitions. Just add an entry in `tsconfig.json`. | ||
|
||
<code-group> | ||
<code-block label="Nuxt 2.9+" active> | ||
|
||
```json{}[tsconfig.json] | ||
{ | ||
"compilerOptions": { | ||
"types": ["@nuxt/types", "nuxt-shopify"] | ||
} | ||
} | ||
``` | ||
|
||
</code-block> | ||
<code-block label="Nuxt < 2.9"> | ||
|
||
```json{}[tsconfig.json] | ||
{ | ||
"compilerOptions": { | ||
"types": ["@nuxt/vue-app", "nuxt-shopify"] | ||
} | ||
} | ||
``` | ||
|
||
</code-block> | ||
|
||
</code-group> |
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,25 @@ | ||
--- | ||
title: Components | ||
description: '' | ||
position: 3 | ||
category: 'Usage' | ||
--- | ||
|
||
## `asyncData` | ||
|
||
```ts | ||
async asyncData({ $shopify, params }) { | ||
const product = await $shopify.product.fetch(params.id); | ||
return { product }; | ||
} | ||
``` | ||
|
||
## `methods`/`created`/`mounted`/etc | ||
|
||
```ts | ||
methods: { | ||
async fetchProduct(productId) { | ||
this.product = await this.$shopify.product.fetch(productId); | ||
} | ||
} | ||
``` |
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,172 @@ | ||
--- | ||
title: Shopify Client | ||
description: '' | ||
position: 5 | ||
category: 'Usage' | ||
--- | ||
|
||
<a href="https://github.com/Shopify/js-buy-sdk/blob/master/README.md#examples">Examples</a> from the official shopify-buy sdk library | ||
|
||
### Fetching products | ||
|
||
```ts | ||
// Fetch all products in your shop | ||
this.$shopify.product.fetchAll().then((products) => { | ||
// Do something with the products | ||
console.log(products); | ||
}); | ||
|
||
// Fetch a single product by ID | ||
const productId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ='; | ||
|
||
this.$shopify.product.fetch(productId).then((product) => { | ||
// Do something with the product | ||
console.log(product); | ||
}); | ||
``` | ||
|
||
### Fetching Collections | ||
|
||
```ts | ||
// Fetch all collections, including their products | ||
this.$shopify.collection.fetchAllWithProducts().then((collections) => { | ||
// Do something with the collections | ||
console.log(collections); | ||
console.log(collections[0].products); | ||
}); | ||
|
||
// Fetch a single collection by ID, including its products | ||
const collectionId = 'Z2lkOi8vc2hvcGlmeS9Db2xsZWN0aW9uLzM2OTMxMjU4NA=='; | ||
|
||
this.$shopify.collection.fetchWithProducts(collectionId).then((collection) => { | ||
// Do something with the collection | ||
console.log(collection); | ||
console.log(collection.products); | ||
}); | ||
``` | ||
|
||
### Creating a checkout | ||
|
||
```ts | ||
// Create an empty checkout | ||
this.$shopify.checkout.create().then((checkout) => { | ||
// Do something with the checkout | ||
console.log(checkout); | ||
}); | ||
``` | ||
|
||
### Adding Line Items | ||
|
||
```ts | ||
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout | ||
const lineItemsToAdd = [ | ||
{ | ||
variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yOTEwNjAyMjc5Mg==', | ||
quantity: 5, | ||
customAttributes: [{ key: 'MyKey', value: 'MyValue' }], | ||
}, | ||
]; | ||
|
||
// Add an item to the checkout | ||
this.$shopify.checkout.addLineItems(checkoutId, lineItemsToAdd).then((checkout) => { | ||
// Do something with the updated checkout | ||
console.log(checkout.lineItems); // Array with one additional line item | ||
}); | ||
``` | ||
|
||
### Updating checkout attributes | ||
|
||
```ts | ||
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9DaGVja291dC9kMTZmM2EzMDM4Yjc4N='; | ||
const input = { customAttributes: [{ key: 'MyKey', value: 'MyValue' }] }; | ||
|
||
this.$shopify.checkout.updateAttributes(checkoutId, input).then((checkout) => { | ||
// Do something with the updated checkout | ||
}); | ||
``` | ||
|
||
### Updating Line Items | ||
|
||
```ts | ||
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout | ||
const lineItemsToUpdate = [{ id: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=', quantity: 2 }]; | ||
|
||
// Update the line item on the checkout (change the quantity or variant) | ||
this.$shopify.checkout.updateLineItems(checkoutId, lineItemsToUpdate).then((checkout) => { | ||
// Do something with the updated checkout | ||
console.log(checkout.lineItems); // Quantity of line item 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=' updated to 2 | ||
}); | ||
``` | ||
|
||
### Removing Line Items | ||
|
||
```ts | ||
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout | ||
const lineItemIdsToRemove = ['Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=']; | ||
|
||
// Remove an item from the checkout | ||
this.$shopify.checkout.removeLineItems(checkoutId, lineItemIdsToRemove).then((checkout) => { | ||
// Do something with the updated checkout | ||
console.log(checkout.lineItems); // Checkout with line item 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=' removed | ||
}); | ||
``` | ||
|
||
### Fetching a Checkout | ||
|
||
```ts | ||
const checkoutId = '2U4NWNkYzI4ZWEyOTdlOD9rZXk9MDVjMzY3Zjk3YWM0YWJjNGRhMTkwMDgwYTUzOGJmYmI='; | ||
|
||
this.$shopify.checkout.fetch(checkoutId).then((checkout) => { | ||
// Do something with the checkout | ||
console.log(checkout); | ||
}); | ||
``` | ||
|
||
### Adding a Discount | ||
|
||
```ts | ||
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout | ||
const discountCode = 'best-discount-ever'; | ||
|
||
// Add a discount code to the checkout | ||
this.$shopify.checkout.addDiscount(checkoutId, discountCode).then((checkout) => { | ||
// Do something with the updated checkout | ||
console.log(checkout); | ||
}); | ||
``` | ||
|
||
### Removing a Discount | ||
|
||
```ts | ||
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout | ||
|
||
// Removes the applied discount from an existing checkout. | ||
this.$shopify.checkout.removeDiscount(checkoutId).then((checkout) => { | ||
// Do something with the updated checkout | ||
console.log(checkout); | ||
}); | ||
``` | ||
|
||
### Updating a Shipping Address | ||
|
||
```ts | ||
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout | ||
|
||
const shippingAddress = { | ||
address1: 'Chestnut Street 92', | ||
address2: 'Apartment 2', | ||
city: 'Louisville', | ||
company: null, | ||
country: 'United States', | ||
firstName: 'Bob', | ||
lastName: 'Norman', | ||
phone: '555-625-1199', | ||
province: 'Kentucky', | ||
zip: '40202', | ||
}; | ||
|
||
// Update the shipping address for an existing checkout. | ||
this.$shopify.checkout.updateShippingAddress(checkoutId, shippingAddress).then((checkout) => { | ||
// Do something with the updated checkout | ||
}); | ||
``` |
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,20 @@ | ||
--- | ||
title: Store actions | ||
description: '' | ||
position: 4 | ||
category: 'Usage' | ||
--- | ||
|
||
## Store actions (including `nuxtServerInit`) | ||
|
||
```ts | ||
// In store | ||
{ | ||
actions: { | ||
async fetchAllProducts ({ commit }) { | ||
const products = await this.$shopify.product.fetchAll(); | ||
commit('SET_PRODUCTS', products) | ||
} | ||
} | ||
} | ||
``` |
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,11 @@ | ||
{ | ||
"title": "Nuxt Shopify", | ||
"url": "https://nuxt-shopify-docs.vercel.app/", | ||
"logo": { | ||
"light": "/logo-light.svg", | ||
"dark": "/logo-dark.svg" | ||
}, | ||
"github": "Gomah/nuxt-shopify", | ||
"twitter": "@gomah", | ||
"defaultBranch": "master" | ||
} |
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,7 @@ | ||
import theme from '@nuxt/content-theme-docs'; | ||
|
||
export default theme({ | ||
docs: { | ||
primaryColor: '#008060', | ||
}, | ||
}); |
Oops, something went wrong.