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 c38506f1c..440823f67 100644 --- a/src/fmg-components/cart/cart.vue +++ b/src/fmg-components/cart/cart.vue @@ -131,7 +131,7 @@ export default { this.cartItems.forEach((cartItem) => { packageContentTypes.forEach((vapType) => { - if (vapType == cartItem.cartItemType) { + if (cartItem.cartItemType.includes(vapType)) { vapsCartItemsForSelectedPackage.push(cartItem); } }); @@ -179,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) { @@ -191,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; }, }, @@ -253,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); @@ -288,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, @@ -324,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, @@ -383,61 +406,31 @@ 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.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; + cartItem.salesTax += childPartLineItem.salesTax; + }); + } }); } @@ -464,15 +457,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; @@ -511,6 +504,41 @@ 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 b7237d2b0..aa82ecaf1 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 fa8add4bb..0e556059d 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1291,6 +1291,7 @@ export const actions = { }); syncLineItemIds(response.data, context.getters.order.lineItems.vaps); + return response; }, @@ -2172,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,