From 5583070c2ca4275c03dbbf6b1df8ed18a16c515d Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Mon, 30 Oct 2023 15:46:48 -0400 Subject: [PATCH 1/2] Fixed calculation issue, added promo cart items --- src/constants/cart-item-types.js | 5 +- src/fmg-components/cart/cart.vue | 154 ++++++++++-------- src/layouts/payment-method/payment-method.vue | 5 +- src/store/index.js | 7 +- 4 files changed, 92 insertions(+), 79 deletions(-) diff --git a/src/constants/cart-item-types.js b/src/constants/cart-item-types.js index 62bc40012..858aa1e8e 100644 --- a/src/constants/cart-item-types.js +++ b/src/constants/cart-item-types.js @@ -1,11 +1,12 @@ const cartItemTypes = { - FRONT_WIPER: "FRONT WIPER", - REAR_WIPER: "REAR WIPER", + FRONT_WIPERS: "FRONT WIPERS", + REAR_WIPERS: "REAR WIPERS", SUPPORTING_ITEMS: "SUPPORTING ITEMS", GLASS_PARTS: "GLASS PARTS", RAIN_DEFENSE: "RAIN DEFENSE", RECYCLE_FEE: "RECYCLE FEE", MOBILE_FEE: "MOBILE FEE", + PROMOS: "PROMOS", }; export { cartItemTypes }; diff --git a/src/fmg-components/cart/cart.vue b/src/fmg-components/cart/cart.vue index c48f48582..cab425157 100644 --- a/src/fmg-components/cart/cart.vue +++ b/src/fmg-components/cart/cart.vue @@ -129,11 +129,9 @@ export default { let vapsCartItemsForSelectedPackage = []; - console.log(this.cartItems); - console.log(packageContentTypes); this.cartItems.forEach((cartItem) => { packageContentTypes.forEach((vapType) => { - if (vapType == cartItem.cartItemType) { + if (cartItem.cartItemType.includes(vapType)) { vapsCartItemsForSelectedPackage.push(cartItem); } }); @@ -153,17 +151,10 @@ export default { return vapsTypeName.Text; }, removeItem(cartItemType, category) { - console.log( - this.lineItems[category].filter( - (lineItemsToKeep) => lineItemsToKeep.cartItemType != cartItemType - ) - ); this.lineItems[category] = this.lineItems[category].filter( (lineItemsToKeep) => lineItemsToKeep.cartItemType != cartItemType ); - //console.log(`lineItemToDelete: ${lineItemIdToDelete}`) - this.$emit("update:modelValue", this.lineItems); }, }, @@ -188,8 +179,8 @@ export default { cartItems.push(this.glassPartsCartItem); } - if (this.supportingItemsCartItem) { - cartItems.push(this.supportingItemsCartItem); + if (this.otherSupportingItemsCartItem) { + cartItems.push(this.otherSupportingItemsCartItem); } if (this.recycleFeeCartItem) { @@ -200,6 +191,25 @@ export default { cartItems.push(this.mobileFeeCartItem); } + // Create a cart item for each promo + this.promos.forEach((promoLineItem) => { + let cartItem = null; + + cartItem = { + name: "Some Kind of Promo", // get from CMS? + category: cartItemCategories.PROMOS, + cartItemType: promoLineItem.partType, + isDisplayed: true, + subTotal: + (promoLineItem.kitPrice ?? 0) + + (promoLineItem.laborAmount ?? 0) + + (promoLineItem.sellingPrice ?? 0), + salesTax: promoLineItem.salesTax, + }; + + cartItems.push(cartItem); + }); + return cartItems; }, }, @@ -262,6 +272,10 @@ export default { const supportingItems = this.lineItems?.supportingItems; return supportingItems?.length > 0 ? supportingItems : []; }, + promos() { + const promos = this.lineItems?.promos; + return promos?.length > 0 ? promos : []; + }, // Cart Items packageCartItems() { return this.getVapsCartItemsForSelectedPackage(this.packageLevel); @@ -269,8 +283,6 @@ export default { nonpackageCartItems() { const nonpackageCartItems = []; - console.log("packageCartItems"); - this.cartItems.forEach((cartItem) => { if (cartItem == this.recycleFeeCartItem || cartItem == this.mobileFeeCartItem) { return; @@ -299,7 +311,7 @@ export default { cartItem = { name: this.frontWiperCartItemName, category: cartItemCategories.VAPS, - cartItemType: cartItemTypes.FRONT_WIPER, + cartItemType: cartItemTypes.FRONT_WIPERS, isDisplayed: true, subTotal: 0, salesTax: 0, @@ -335,7 +347,7 @@ export default { cartItem = { name: this.rearWiperCartItemName, category: cartItemCategories.VAPS, - cartItemType: cartItemTypes.REAR_WIPER, + cartItemType: cartItemTypes.REAR_WIPERS, isDisplayed: true, subTotal: 0, salesTax: 0, @@ -394,61 +406,30 @@ export default { glassPartsCartItem() { let cartItem = null; - const flattenedGlassPartsLineItems = - this.lineItemUtilities.getFlattenedArrayOfLineItemsWithChildParts( - this.lineItems.glassParts - ); + if (this.lineItems?.glassParts?.length > 0) { + this.lineItems?.glassParts?.forEach((lineItem) => { + cartItem = { + name: null, + category: cartItemCategories.GLASS_PARTS, + cartItemType: cartItemTypes.GLASS_PARTS, + isDisplayed: false, + subTotal: (lineItem.kitPrice ?? 0) + + (lineItem.laborAmount ?? 0) + + (lineItem.sellingPrice ?? 0), + salesTax: lineItem.salesTax ?? 0, + lineItems: [], + }; - if (flattenedGlassPartsLineItems.length > 0) { - cartItem = { - name: null, - category: cartItemCategories.GLASS_PARTS, - cartItemType: cartItemTypes.GLASS_PARTS, - isDisplayed: false, - subTotal: 0, - salesTax: 0, - lineItems: [], - }; + if (lineItem.childParts?.length > 0) { + lineItem.childParts.forEach((childPartLineItem) => { + cartItem.subTotal += (childPartLineItem.kitPrice ?? 0) + + (childPartLineItem.laborAmount ?? 0) + + (childPartLineItem.sellingPrice ?? 0); - flattenedGlassPartsLineItems.forEach((lineItem) => { - lineItem.cartItemType = cartItem.cartItemType; - cartItem.lineItems.push(lineItem); + cartItem.salesTax += childPartLineItem.salesTax; + }) + } - cartItem.subTotal += - (lineItem.kitPrice ?? 0) + - (lineItem.laborAmount ?? 0) + - (lineItem.sellingPrice ?? 0); - - cartItem.salesTax += lineItem.salesTax ?? 0; - }); - } - - return cartItem; - }, - supportingItemsCartItem() { - let cartItem = null; - - if (this.supportingItems.length > 0) { - cartItem = { - name: null, - category: cartItemCategories.SUPPORTING_ITEMS, - cartItemType: cartItemTypes.SUPPORTING_ITEMS, - isDisplayed: false, - subTotal: 0, - salesTax: 0, - lineItems: [], - }; - - this.supportingItems.forEach((lineItem) => { - lineItem.cartItemType = cartItem.cartItemType; - cartItem.lineItems.push(lineItem); - - cartItem.subTotal += - (lineItem.kitPrice ?? 0) + - (lineItem.laborAmount ?? 0) + - (lineItem.sellingPrice ?? 0); - - cartItem.salesTax += lineItem.salesTax ?? 0; }); } @@ -475,15 +456,15 @@ export default { lineItems: [], }; - recycleFeeLineItem.cartItemType = cartItem.cartItemType; - cartItem.lineItems.push(recycleFeeLineItem); + //recycleFeeLineItem.cartItemType = cartItem.cartItemType; + //cartItem.lineItems.push(recycleFeeLineItem); cartItem.subTotal += (recycleFeeLineItem.kitPrice ?? 0) + (recycleFeeLineItem.laborAmount ?? 0) + (recycleFeeLineItem.sellingPrice ?? 0); - cartItem.salesTax += recycleFeeLineItem.salesTax ?? 0; + cartItem.salesTax = recycleFeeLineItem.salesTax ?? 0; } return cartItem; @@ -522,6 +503,37 @@ export default { return cartItem; }, + otherSupportingItemsCartItem() { + let cartItem = null; + + const otherSupportingItemsLineItems = this.supportingItems.filter(lineItem => lineItem.partNumber != partTypeStrings.MOBILE_FEE && lineItem.partNumber != partTypeStrings.RECYCLE_FEE); + + if (otherSupportingItemsLineItems.length > 0) { + cartItem = { + name: null, + category: cartItemCategories.SUPPORTING_ITEMS, + cartItemType: cartItemTypes.SUPPORTING_ITEMS, + isDisplayed: false, + subTotal: 0, + salesTax: 0, + lineItems: [], + }; + + otherSupportingItemsLineItems.forEach((lineItem) => { + lineItem.cartItemType = cartItem.cartItemType; + cartItem.lineItems.push(lineItem); + + cartItem.subTotal += + (lineItem.kitPrice ?? 0) + + (lineItem.laborAmount ?? 0) + + (lineItem.sellingPrice ?? 0); + + cartItem.salesTax += lineItem.salesTax ?? 0; + }); + } + + return cartItem; + }, removeLinkText() { return this.getCmsContent("RemoveCartItemTextWidget", "Text"); }, diff --git a/src/layouts/payment-method/payment-method.vue b/src/layouts/payment-method/payment-method.vue index 59e17d92d..25715b39f 100644 --- a/src/layouts/payment-method/payment-method.vue +++ b/src/layouts/payment-method/payment-method.vue @@ -90,7 +90,7 @@ import { defineRule } from "vee-validate"; import { required } from "@/helpers/validation-rules"; import { errorMessages } from "@/constants/error-messages"; import { AppointmentTypeStrings } from "@/constants/schedule-constants"; -import { LineItemUtilities, mapTaxedAvailableLineItemsToStoreFormat } from "../../store"; +import { mapTaxedAvailableLineItemsToStoreFormat } from "../../store"; defineRule("option-required", required(errorMessages.OPTION_REQUIRED)); @@ -174,9 +174,6 @@ export default { false ); - const lineItemUtilities = new LineItemUtilities(); - lineItemUtilities.addGuidToLineItemsIfNotAlreadyThere(availableLineItems); - const lineItems = mapTaxedAvailableLineItemsToStoreFormat( availableLineItems, lineItemsFromStore diff --git a/src/store/index.js b/src/store/index.js index 6a9be935e..0e556059d 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1291,7 +1291,7 @@ export const actions = { }); syncLineItemIds(response.data, context.getters.order.lineItems.vaps); - console.log(response.data); + return response; }, @@ -2173,7 +2173,10 @@ export const actions = { pageNameToLog, } ) { - const lineItemsWithOnlyPriceInfo = pricedAvailableLineItems.map((lineItem) => ({ + const flattenedLineItemsWithChildParts = + getFlattenedArrayOfLineItemsWithChildParts(pricedAvailableLineItems); + + const lineItemsWithOnlyPriceInfo = flattenedLineItemsWithChildParts.map((lineItem) => ({ partNumber: lineItem.partNumber, laborAmount: lineItem.laborAmount ?? 0, kitPrice: lineItem.kitPrice ?? 0, From 5472b8b3f879f27c3fc3dd006d1ddcd7446e2f45 Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Mon, 30 Oct 2023 15:48:32 -0400 Subject: [PATCH 2/2] Prettified --- src/fmg-components/cart/cart.vue | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/fmg-components/cart/cart.vue b/src/fmg-components/cart/cart.vue index cab425157..440823f67 100644 --- a/src/fmg-components/cart/cart.vue +++ b/src/fmg-components/cart/cart.vue @@ -413,23 +413,24 @@ export default { category: cartItemCategories.GLASS_PARTS, cartItemType: cartItemTypes.GLASS_PARTS, isDisplayed: false, - subTotal: (lineItem.kitPrice ?? 0) + - (lineItem.laborAmount ?? 0) + - (lineItem.sellingPrice ?? 0), + subTotal: + (lineItem.kitPrice ?? 0) + + (lineItem.laborAmount ?? 0) + + (lineItem.sellingPrice ?? 0), salesTax: lineItem.salesTax ?? 0, lineItems: [], }; if (lineItem.childParts?.length > 0) { lineItem.childParts.forEach((childPartLineItem) => { - cartItem.subTotal += (childPartLineItem.kitPrice ?? 0) + - (childPartLineItem.laborAmount ?? 0) + - (childPartLineItem.sellingPrice ?? 0); + cartItem.subTotal += + (childPartLineItem.kitPrice ?? 0) + + (childPartLineItem.laborAmount ?? 0) + + (childPartLineItem.sellingPrice ?? 0); cartItem.salesTax += childPartLineItem.salesTax; - }) + }); } - }); } @@ -506,7 +507,11 @@ export default { otherSupportingItemsCartItem() { let cartItem = null; - const otherSupportingItemsLineItems = this.supportingItems.filter(lineItem => lineItem.partNumber != partTypeStrings.MOBILE_FEE && lineItem.partNumber != partTypeStrings.RECYCLE_FEE); + const otherSupportingItemsLineItems = this.supportingItems.filter( + (lineItem) => + lineItem.partNumber != partTypeStrings.MOBILE_FEE && + lineItem.partNumber != partTypeStrings.RECYCLE_FEE + ); if (otherSupportingItemsLineItems.length > 0) { cartItem = {