From 32cb21b75844e974dededc0ae16b8b7c2a9fd45a Mon Sep 17 00:00:00 2001 From: sergiosentry <109162568+serglom21@users.noreply.github.com> Date: Tue, 12 Nov 2024 10:58:22 -0500 Subject: [PATCH 1/5] add checkout component --- vue/src/App.vue | 1 + vue/src/router/index.js | 6 + vue/src/stores/cart.js | 39 +++-- vue/src/views/CheckoutView.vue | 295 +++++++++++++++++++++++++++++++++ vue/src/views/ProductsView.vue | 26 +-- 5 files changed, 330 insertions(+), 37 deletions(-) create mode 100644 vue/src/views/CheckoutView.vue 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..ef389385 100644 --- a/vue/src/stores/cart.js +++ b/vue/src/stores/cart.js @@ -11,19 +11,32 @@ export const useCounterStore = defineStore({ this.counter += val; }, 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..89b2dd7b --- /dev/null +++ b/vue/src/views/CheckoutView.vue @@ -0,0 +1,295 @@ + + + + + \ 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 }})
From f1bb45dce89670d18392d17604f16c4f684c69e4 Mon Sep 17 00:00:00 2001 From: sergiosentry <109162568+serglom21@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:03:14 -0500 Subject: [PATCH 2/5] get body from cart object --- vue/src/views/CheckoutView.vue | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/vue/src/views/CheckoutView.vue b/vue/src/views/CheckoutView.vue index 89b2dd7b..d2949a11 100644 --- a/vue/src/views/CheckoutView.vue +++ b/vue/src/views/CheckoutView.vue @@ -121,14 +121,13 @@ import { useCounterStore } from "../stores/cart"; let success = null; Sentry.startSpan({ name: "Checkout" }, 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}}'; + let cartJson = JSON.stringify({ cart: this.cartItems}) var requestOptions = { method: "POST", headers: { "Content-Type": "text/plain", }, - body: raw, + body: cartJson, redirect: "follow", }; From bbffbdcfc27ab22f2c014ff2566bd47a03a51a1a Mon Sep 17 00:00:00 2001 From: sergiosentry <109162568+serglom21@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:20:19 -0500 Subject: [PATCH 3/5] adding form object to payload --- vue/src/views/CheckoutView.vue | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/vue/src/views/CheckoutView.vue b/vue/src/views/CheckoutView.vue index d2949a11..bc0b985e 100644 --- a/vue/src/views/CheckoutView.vue +++ b/vue/src/views/CheckoutView.vue @@ -121,7 +121,17 @@ import { useCounterStore } from "../stores/cart"; let success = null; Sentry.startSpan({ name: "Checkout" }, async () => { - let cartJson = JSON.stringify({ cart: this.cartItems}) + let cartJson = JSON.stringify({ cart: this.cartItems, form: { + email, + subscribe, + firstName, + lastName, + address, + city, + country, + state, + zipCode + }}) var requestOptions = { method: "POST", headers: { From 2127192b0bbfa2926ba16ed3ae124c5318a500e2 Mon Sep 17 00:00:00 2001 From: sergiosentry <109162568+serglom21@users.noreply.github.com> Date: Tue, 12 Nov 2024 13:10:06 -0500 Subject: [PATCH 4/5] fix form parameters --- vue/src/views/CheckoutView.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/vue/src/views/CheckoutView.vue b/vue/src/views/CheckoutView.vue index bc0b985e..16b10396 100644 --- a/vue/src/views/CheckoutView.vue +++ b/vue/src/views/CheckoutView.vue @@ -123,7 +123,6 @@ import { useCounterStore } from "../stores/cart"; Sentry.startSpan({ name: "Checkout" }, async () => { let cartJson = JSON.stringify({ cart: this.cartItems, form: { email, - subscribe, firstName, lastName, address, From 0df3e28b9e0f2ed6b872a5233b892ca8090b9652 Mon Sep 17 00:00:00 2001 From: sergiosentry <109162568+serglom21@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:00:44 -0500 Subject: [PATCH 5/5] creating new trace for checkout page --- vue/src/stores/cart.js | 14 +++++++ vue/src/views/CheckoutView.vue | 77 +++++++++++++++++++++------------- 2 files changed, 61 insertions(+), 30 deletions(-) diff --git a/vue/src/stores/cart.js b/vue/src/stores/cart.js index ef389385..2921436b 100644 --- a/vue/src/stores/cart.js +++ b/vue/src/stores/cart.js @@ -10,6 +10,20 @@ 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) { let index = this.cart.findIndex( item => item.id === product.id); if (index === -1) { diff --git a/vue/src/views/CheckoutView.vue b/vue/src/views/CheckoutView.vue index 16b10396..d5a702b1 100644 --- a/vue/src/views/CheckoutView.vue +++ b/vue/src/views/CheckoutView.vue @@ -87,7 +87,22 @@ import { useCounterStore } from "../stores/cart"; return this.store.getCartItems(); }, cartTotal() { - return this.store.cartTotal; // example if you have a cart total in the store + return this.store.getTotalPrice(); // example if you have a cart total in the store + }, + cartQuantities(){ + return this.store.getQuantities() + }, + contactForm(){ + return { + email, + firstName, + lastName, + address, + city, + country, + state, + zipCode + } } }, methods: { @@ -120,35 +135,37 @@ import { useCounterStore } from "../stores/cart"; handleSubmit() { let success = null; - Sentry.startSpan({ name: "Checkout" }, async () => { - let cartJson = JSON.stringify({ cart: this.cartItems, form: { - email, - firstName, - lastName, - address, - city, - country, - state, - zipCode - }}) - var requestOptions = { - method: "POST", - headers: { - "Content-Type": "text/plain", - }, - body: cartJson, - redirect: "follow", - }; - - try { - success = await this.makeCheckoutRequest(requestOptions); - } catch (error) { - Sentry.captureException(error); - this.$router.push("/error"); - - } - - return success; + Sentry.startNewTrace(() => { + Sentry.startSpan({ name: "Checkout" }, async (span) => { + const payload = { + cart: { + items: this.cartItems, + quantities: this.cartQuantities, + total: this.cartTotal, + }, + form: this.contactForm, + } + var requestOptions = { + method: "POST", + headers: { + "Content-Type": "text/plain", + }, + body: JSON.stringify(payload), + redirect: "follow", + }; + + try { + success = await this.makeCheckoutRequest(requestOptions); + } catch (error) { + Sentry.withActiveSpan(span, async () => { + Sentry.captureException(error); + }) + this.$router.push("/error"); + + } + + return success; + }) }) if (!success) {