Installations
npm install nuxt-shopify
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
20.13.1
NPM Version
10.5.2
Statistics
353 Stars
1,280 Commits
29 Forks
6 Watching
19 Branches
3 Contributors
Updated on 20 Oct 2024
Bundle Size
2.81 kB
Minified
1.36 kB
Minified + Gzipped
Languages
TypeScript (38.95%)
Vue (30.88%)
JavaScript (30.17%)
Total Downloads
Cumulative downloads
Total Downloads
317,783
Last day
17.3%
569
Compared to previous day
Last week
1.7%
3,406
Compared to previous week
Last month
0.5%
14,473
Compared to previous month
Last year
157%
147,441
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Dev Dependencies
25
🛍 Shopify Module
Easy Shopify Buy client integration with Nuxt.js
Setup
Install with yarn:
1yarn add nuxt-shopify
Install with npm:
1npm install nuxt-shopify
nuxt.config.js
1module.exports = { 2 modules: ['nuxt-shopify'], 3 4 shopify: { 5 /** 6 * Your shopify domain 7 */ 8 domain: 'your-shop-name.myshopify.com', 9 10 /** 11 * Your shopify storefront access token 12 */ 13 storefrontAccessToken: 'your-storefront-access-token', 14 15 /** 16 * This will be larger than the optimized version, as it will contain all fields that are available in the 17 * Storefront API. (https://help.shopify.com/en/api/custom-storefronts/storefront-api/reference) 18 * This should only be used when you need to add custom queries to supplement the JS Buy SDK queries. 19 */ 20 unoptimized: false, 21 22 /** 23 * Set language to return translated content (optional) 24 */ 25 language: 'ja-JP', 26 }, 27};
OR
1module.exports = { 2 modules: ['nuxt-shopify'], 3 4 env: { 5 SHOPIFY_DOMAIN: 'your-shop-name.myshopify.com', // your shopify domain 6 SHOPIFY_ACCESS_TOKEN: 'your-storefront-access-token', // your shopify storefront access token 7 }, 8};
Don't have a Storefront Access Token yet? Get started.
Usage
Component
asyncData
1async asyncData({ $shopify, params }) { 2 const product = await $shopify.product.fetch(params.id); 3 return { product }; 4}
methods
/created
/mounted
/etc
1methods: { 2 async fetchProduct(productId) { 3 this.product = await this.$shopify.product.fetch(productId); 4 } 5}
Store actions (including nuxtServerInit
)
1// In store 2{ 3 actions: { 4 async fetchAllProducts ({ commit }) { 5 const products = await this.$shopify.product.fetchAll(); 6 commit('SET_PRODUCTS', products) 7 } 8 } 9}
Shopify Client
Examples from the official shopify-buy sdk library
Fetching products
1// Fetch all products in your shop 2this.$shopify.product.fetchAll().then((products) => { 3 // Do something with the products 4 console.log(products); 5}); 6 7// Fetch a single product by ID 8const productId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ='; 9 10this.$shopify.product.fetch(productId).then((product) => { 11 // Do something with the product 12 console.log(product); 13});
Fetching Collections
1// Fetch all collections, including their products 2this.$shopify.collection.fetchAllWithProducts().then((collections) => { 3 // Do something with the collections 4 console.log(collections); 5 console.log(collections[0].products); 6}); 7 8// Fetch a single collection by ID, including its products 9const collectionId = 'Z2lkOi8vc2hvcGlmeS9Db2xsZWN0aW9uLzM2OTMxMjU4NA=='; 10 11this.$shopify.collection.fetchWithProducts(collectionId).then((collection) => { 12 // Do something with the collection 13 console.log(collection); 14 console.log(collection.products); 15});
Creating a checkout
1// Create an empty checkout 2this.$shopify.checkout.create().then((checkout) => { 3 // Do something with the checkout 4 console.log(checkout); 5});
Adding Line Items
1const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout 2const lineItemsToAdd = [ 3 { 4 variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yOTEwNjAyMjc5Mg==', 5 quantity: 5, 6 customAttributes: [{ key: 'MyKey', value: 'MyValue' }], 7 }, 8]; 9 10// Add an item to the checkout 11this.$shopify.checkout.addLineItems(checkoutId, lineItemsToAdd).then((checkout) => { 12 // Do something with the updated checkout 13 console.log(checkout.lineItems); // Array with one additional line item 14});
Updating checkout attributes
1const checkoutId = 'Z2lkOi8vc2hvcGlmeS9DaGVja291dC9kMTZmM2EzMDM4Yjc4N='; 2const input = { customAttributes: [{ key: 'MyKey', value: 'MyValue' }] }; 3 4this.$shopify.checkout.updateAttributes(checkoutId, input).then((checkout) => { 5 // Do something with the updated checkout 6});
Updating Line Items
1const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout 2const lineItemsToUpdate = [{ id: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=', quantity: 2 }]; 3 4// Update the line item on the checkout (change the quantity or variant) 5this.$shopify.checkout.updateLineItems(checkoutId, lineItemsToUpdate).then((checkout) => { 6 // Do something with the updated checkout 7 console.log(checkout.lineItems); // Quantity of line item 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=' updated to 2 8});
Removing Line Items
1const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout 2const lineItemIdsToRemove = ['Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=']; 3 4// Remove an item from the checkout 5this.$shopify.checkout.removeLineItems(checkoutId, lineItemIdsToRemove).then((checkout) => { 6 // Do something with the updated checkout 7 console.log(checkout.lineItems); // Checkout with line item 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=' removed 8});
Fetching a Checkout
1const checkoutId = '2U4NWNkYzI4ZWEyOTdlOD9rZXk9MDVjMzY3Zjk3YWM0YWJjNGRhMTkwMDgwYTUzOGJmYmI='; 2 3this.$shopify.checkout.fetch(checkoutId).then((checkout) => { 4 // Do something with the checkout 5 console.log(checkout); 6});
Adding a Discount
1const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout 2const discountCode = 'best-discount-ever'; 3 4// Add a discount code to the checkout 5this.$shopify.checkout.addDiscount(checkoutId, discountCode).then((checkout) => { 6 // Do something with the updated checkout 7 console.log(checkout); 8});
Removing a Discount
1const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout 2 3// Removes the applied discount from an existing checkout. 4this.$shopify.checkout.removeDiscount(checkoutId).then((checkout) => { 5 // Do something with the updated checkout 6 console.log(checkout); 7});
Updating a Shipping Address
1const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout 2 3const shippingAddress = { 4 address1: 'Chestnut Street 92', 5 address2: 'Apartment 2', 6 city: 'Louisville', 7 company: null, 8 country: 'United States', 9 firstName: 'Bob', 10 lastName: 'Norman', 11 phone: '555-625-1199', 12 province: 'Kentucky', 13 zip: '40202', 14}; 15 16// Update the shipping address for an existing checkout. 17this.$shopify.checkout.updateShippingAddress(checkoutId, shippingAddress).then((checkout) => { 18 // Do something with the updated checkout 19});
Development
- Clone this repository
- Install dependencies using
yarn install
ornpm install
- Build the module using
yarn build
ornpm run build
- Start development server using
yarn dev
ornpm run dev
📑 License
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/29 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/Gomah/nuxt-shopify/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/Gomah/nuxt-shopify/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/Gomah/nuxt-shopify/main.yml/master?enable=pin
- Info: 0 out of 3 GitHub-owned GitHubAction dependencies pinned
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 1 are checked with a SAST tool
Reason
44 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-pfq8-rq6v-vf5m
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-fq9m-v26v-2m4f
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj
- Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-vf6r-87q4-2vjf
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-hwj9-h5mp-3pm3
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-5j4c-8p2g-v4jx
- Warn: Project is vulnerable to: GHSA-g3ch-rx76-35fx
- Warn: Project is vulnerable to: GHSA-wr3j-pwj9-hqq6
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-776f-qx25-q3cc
Score
2.5
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to nuxt-shopify
@konkonam/nuxt-shopify
Easily integrate shopify into your nuxt 3 & 4 project 🚀
@shopify/cli-kit
A set of utilities, interfaces, and models that are common across all the platform features
@shopify/cli
A CLI tool to build for the Shopify platform
@nuxtjs/opencollective
[![npm version][npm-v-src]][npm-v-href] [![npm downloads][npm-d-src]][npm-d-href] [![status][github-actions-src]][github-actions-href]