diff --git a/vue/src/App.vue b/vue/src/App.vue index fb6aca6c..0e8da955 100644 --- a/vue/src/App.vue +++ b/vue/src/App.vue @@ -13,6 +13,7 @@ import { RouterLink, RouterView } from "vue-router"; diff --git a/vue/src/router/index.js b/vue/src/router/index.js index e9ebbee3..4675a758 100644 --- a/vue/src/router/index.js +++ b/vue/src/router/index.js @@ -6,6 +6,7 @@ import SubscribeView from '../views/SubscribeView.vue' import ErrorView from '../views/ErrorView.vue' import HomePage from "../components/HomePage.vue"; import ProductsView from "../views/ProductsView.vue"; +import CheckoutView from "../views/CheckoutView.vue"; const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), @@ -44,6 +45,11 @@ const router = createRouter({ name: "trigger", component: ManualView, }, + { + path: "/checkout", + name: "checkout", + component: CheckoutView + } ], }); diff --git a/vue/src/stores/cart.js b/vue/src/stores/cart.js index 152b2a09..2921436b 100644 --- a/vue/src/stores/cart.js +++ b/vue/src/stores/cart.js @@ -10,20 +10,47 @@ export const useCounterStore = defineStore({ updatePrice(val = 1) { this.counter += val; }, + getQuantities(){ + let quantities = {} + for (let item in this.cart) { + quantities[this.cart[item].id] = this.cart[item].count + } + return quantities; + }, + getTotalPrice(){ + let total = 0; + for (let item in this.cart) { + total += this.cart[item].totalPrice + } + return total; + }, updateCart(product) { - this.cart.push(product); - console.log("cart", this.cart); - // if (this.cart.length() > 0) { - // this.cart.forEach((eachCartItem) => { - // if (eachCartItem.id === product.id) { - // return; - // } else { - // this.cart.push(product); - // } - // }); - // } else { - // this.cart.push(product); - // } + let index = this.cart.findIndex( item => item.id === product.id); + if (index === -1) { + product.count = 1 + product.totalPrice = product.price; + this.cart.push(product); + } else { + this.cart[index].totalPrice += product.price; + this.cart[index].count += 1; + } + }, + getCartItems() { + return this.cart + }, + decreaseQuantity(item){ + const index = this.cart.findIndex(cartItem => cartItem.id === item.id); + if (index !== -1) { + this.cart[index].count--; + this.cart[index].totalPrice -= this.cart[index].price; + } }, + increaseQuantity(item){ + const index = this.cart.findIndex(cartItem => cartItem.id === item.id); + if (index !== -1) { + this.cart[index].count++; + this.cart[index].totalPrice += this.cart[index].price; + } + } }, }); diff --git a/vue/src/views/CheckoutView.vue b/vue/src/views/CheckoutView.vue new file mode 100644 index 00000000..d5a702b1 --- /dev/null +++ b/vue/src/views/CheckoutView.vue @@ -0,0 +1,320 @@ + + + + + \ No newline at end of file diff --git a/vue/src/views/ProductsView.vue b/vue/src/views/ProductsView.vue index c82a0530..57d634d8 100644 --- a/vue/src/views/ProductsView.vue +++ b/vue/src/views/ProductsView.vue @@ -39,29 +39,7 @@ export default { }); }, checkout: function () { - this.disabledStatus = true; - let internalTagSE = this.SE; - let success = null; - - Sentry.startSpan({ name: "Checkout", forceTransaction: true}, async () => { - var raw = - '{"cart":{"items":[{"id":4,"title":"Botana Voice","description":"Lets plants speak for themselves.","descriptionfull":"Now we don\'t want him to get lonely, so we\'ll give him a little friend. Let your imagination just wonder around when you\'re doing these things. Let your imagination be your guide. Nature is so fantastic, enjoy it. Let it make you happy.","price":175,"img":"https://storage.googleapis.com/application-monitoring/plant-to-text.jpg","imgcropped":"https://storage.googleapis.com/application-monitoring/plant-to-text-cropped.jpg","pg_sleep":"","reviews":[{"id":4,"productid":4,"rating":4,"customerid":null,"description":null,"created":"2021-06-04 00:12:33.553939","pg_sleep":""},{"id":5,"productid":4,"rating":3,"customerid":null,"description":null,"created":"2021-06-04 00:12:45.558259","pg_sleep":""},{"id":6,"productid":4,"rating":2,"customerid":null,"description":null,"created":"2021-06-04 00:12:50.510322","pg_sleep":""},{"id":13,"productid":4,"rating":3,"customerid":null,"description":null,"created":"2021-07-01 00:12:43.312186","pg_sleep":""},{"id":14,"productid":4,"rating":3,"customerid":null,"description":null,"created":"2021-07-01 00:12:54.719873","pg_sleep":""},{"id":15,"productid":4,"rating":3,"customerid":null,"description":null,"created":"2021-07-01 00:12:57.760686","pg_sleep":""},{"id":16,"productid":4,"rating":3,"customerid":null,"description":null,"created":"2021-07-01 00:13:00.140407","pg_sleep":""},{"id":17,"productid":4,"rating":3,"customerid":null,"description":null,"created":"2021-07-01 00:13:00.971730","pg_sleep":""},{"id":18,"productid":4,"rating":3,"customerid":null,"description":null,"created":"2021-07-01 00:13:01.665798","pg_sleep":""},{"id":19,"productid":4,"rating":3,"customerid":null,"description":null,"created":"2021-07-01 00:13:02.278934","pg_sleep":""}]}],"quantities":{"4":2},"total":350},"form":{"loading":false}}'; - var requestOptions = { - method: "POST", - headers: { - "Content-Type": "text/plain", - }, - body: raw, - redirect: "follow", - }; - - success = await this.makeCheckoutRequest(requestOptions); - return success; - }) - - if (!success) { - this.$router.push("/error"); - } + this.$router.push("/checkout"); }, addToCartPrice: function () { @@ -117,7 +95,7 @@ export default { :onClick="checkout" :disabled="disabledStatus" > - Checkout your cart ($ {{ checkoutCartPrice }}) + Checkout ($ {{ checkoutCartPrice }})