diff --git a/components/TheNavbar.vue b/components/TheNavbar.vue index 69948ad..c94d7f1 100644 --- a/components/TheNavbar.vue +++ b/components/TheNavbar.vue @@ -20,12 +20,12 @@ diff --git a/mixins/cartMixins.js b/mixins/cartMixins.js index 18ecb45..1495dc0 100644 --- a/mixins/cartMixins.js +++ b/mixins/cartMixins.js @@ -1,10 +1,20 @@ export default { methods: { - addToCart (product) { - this.$store.commit('addToCart', product) - this.$buefy.toast.open({ - message: 'Product added', - type: 'is-success' + addToCart (product, checkout) { + // add to cart + this.$store.dispatch('addItemToCart', product).then((item) => { + // eslint-disable-next-line no-console + console.log('item : ', item) + const lineItemsToAdd = { + variantId: item.variants[0].id, + quantity: item.count + } + // Add an item to the checkout + this.$shopify.checkout.addLineItems(checkout.id, lineItemsToAdd) + this.$buefy.toast.open({ + message: 'Product added', + type: 'is-success' + }) }) } } diff --git a/nuxt.config.js b/nuxt.config.js index ba83c9c..7f8f037 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -52,8 +52,8 @@ export default { axios: { }, shopify: { - domain: 'my-guitares.myshopify.com/', // your shopify domain - storefrontAccessToken: '584f71cdb63bca9d98db7ce872414df2'// your shopify storefront access token + domain: 'home-deco35.myshopify.com/', // your shopify domain + storefrontAccessToken: '63f6a2f53bbc44bfc9e40c911bb17a7e'// your shopify storefront access token }, /* ** Build configuration diff --git a/package-lock.json b/package-lock.json index ccbc71d..d2aa0cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2671,12 +2671,6 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.3.0.tgz", "integrity": "sha512-/czfa8BwS88b9gWQVhc8eknunSA2DoJpJyTQkhheIf5E48u1N0R4q/YxxsAeqRrmK9TQ/uYfgLDfZo91UlANIA==" }, - "acorn-jsx": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.0.2.tgz", - "integrity": "sha512-tiNTrP1MP0QrChmD2DdupCr6HWSFeKVw5d/dHTu4Y7rkAkRhU/Dt7dphAfIUyxtHpl/eBVip5uTNSpQJHylpAw==", - "dev": true - }, "acorn-walk": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.2.0.tgz", diff --git a/pages/basket/index.vue b/pages/basket/index.vue index e9e7c44..caeaad9 100644 --- a/pages/basket/index.vue +++ b/pages/basket/index.vue @@ -1,14 +1,41 @@ diff --git a/pages/blog/_handle/index.vue b/pages/blog/_handle/index.vue new file mode 100644 index 0000000..fd224db --- /dev/null +++ b/pages/blog/_handle/index.vue @@ -0,0 +1,15 @@ + + + + + diff --git a/pages/blog/index.vue b/pages/blog/index.vue new file mode 100644 index 0000000..18fdd91 --- /dev/null +++ b/pages/blog/index.vue @@ -0,0 +1,15 @@ + + + + + diff --git a/pages/index.vue b/pages/index.vue index 5e91911..f967e4a 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -9,6 +9,11 @@ export default { async asyncData ({ $shopify }) { const products = await $shopify.product.fetchAll() return { products } + }, + created () { + this.$shopify.checkout.create().then((checkout) => { + this.$store.commit('setCheckout', checkout) + }) } } @@ -17,37 +22,4 @@ export default { .full-width { width: 100%; } - .el-row { - margin-bottom: 20px; - &:last-child { - margin-bottom: 0; - } - } - .el-col { - border-radius: 4px; - } - .bg-purple-dark { - background: #99a9bf; - } - .bg-purple { - background: #d3dce6; - } - .bg-purple-light { - background: #e5e9f2; - } - .grid-content { - border-radius: 4px; - min-height: 36px; - } - .row-bg { - padding: 10px 0; - background-color: #f9fafc; - } - .image { - width: 100%; - height: 15rem; - } - .description { - margin-bottom: 1rem; - } diff --git a/pages/products/index.vue b/pages/products/index.vue index f98bd4e..c249090 100644 --- a/pages/products/index.vue +++ b/pages/products/index.vue @@ -56,6 +56,8 @@ export default { }, async asyncData ({ $shopify, store }) { const products = await $shopify.product.fetchAll() + // eslint-disable-next-line no-console + console.log(products) store.commit('setProducts', products) } } diff --git a/store/index.js b/store/index.js index b155d98..62149be 100644 --- a/store/index.js +++ b/store/index.js @@ -1,22 +1,43 @@ export const state = () => ({ products: [], - cart: [] + cart: [], + checkout: {} }) export const mutations = { setProducts (state, data) { state.products = data }, - addToCart (state, item) { - const element = state.cart.filter(el => el.id === item.id) - if (element.length > 0) { - const index = state.cart.indexOf(element[0]) + setCheckout (state, data) { + state.checkout = data + }, + incrementCart (sate, index) { + state.cart[index].count++ + }, + addCart (state, item) { + item.count = 1 + state.cart.push(item) + } +} + +export const getters = { + getCartItem: state => (id) => { + return state.cart.filter(item => (item.id === id)) + } +} + +export const actions = { + addItemToCart ({ commit, getters }, payload) { + return new Promise((resolve) => { + const element = getters.getCartItem(payload.id) // eslint-disable-next-line no-console - console.log(index) - state.cart[index].count++ - } else { - item.count = 1 - state.cart.push(item) - } + console.log(element) + if (element.length > 0) { + commit('incrementCart', payload.id) + } else { + commit('addCart', payload) + } + resolve(getters.getCartItem(payload.id)[0]) + }) } }