Complete Vue.js 2 Web Development_ Practical guide to building end-to-end web development solutions with Vue.js 2

(singke) #1
Building an E-Commerce Store - Adding a Checkout Chapter 11

The details we're going to store for each product added to the basket are as follows:


Product title
Product handle, so we can link back to the product
Selected variation title (as it appears in the select box)
Currently selected image, so we can show an appropriate image in the Checkout
Variation details, this contains price and weight along with other details
Variation SKU, this will help us identify whether the product has already been
added
Quantity, how many items the user has added to their basket

As we will be storing all this information within an object, contained in an array, we need


to create a placeholder array within the store. Add a new key to the state object within the


store titled basket and make it a blank array:


const store = new Vuex.Store({
state: {
products: {},
categories: {},

categoryHome: {
title: 'Welcome to the Shop',
handle: 'home',
products: [
...
]
},

basket: []

},

mutations: {
...
},

actions: {
...
},

getters: {
...
}
});
Free download pdf