add product to checkout when added to cart

This commit is contained in:
thomas
2020-02-24 20:08:56 +01:00
parent 5ea6dcfaa1
commit ef8c22855f
6 changed files with 75 additions and 63 deletions
+12 -4
View File
@@ -1,16 +1,24 @@
export default {
computed: {
checkout () {
return this.$store.state.checkout
},
cart () {
return this.$store.state.cart
}
},
methods: {
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
quantity: 1
}
// Add an item to the checkout
this.$shopify.checkout.addLineItems(checkout.id, lineItemsToAdd)
this.$shopify.checkout.addLineItems(checkout.id, lineItemsToAdd).then((checkout) => {
this.$store.commit('setCheckout', checkout)
})
this.$buefy.toast.open({
message: 'Product added',
type: 'is-success'