From 5eb4ef0418bae67e24bb1d8f3c3b80917d97d9a1 Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Mon, 13 Apr 2026 10:25:48 -0400 Subject: [PATCH] Moved some common methods around. --- src/helpers/object-helper.js | 14 ++++++++ src/helpers/recal-helper.js | 27 +++++++++++++- src/mixins/analytics-mixin.js | 68 ++++++----------------------------- src/store/index.js | 40 +++------------------ 4 files changed, 56 insertions(+), 93 deletions(-) diff --git a/src/helpers/object-helper.js b/src/helpers/object-helper.js index 37ee46be..e142c236 100644 --- a/src/helpers/object-helper.js +++ b/src/helpers/object-helper.js @@ -86,3 +86,17 @@ export function getPropertyCaseInsensitive(obj, property) { while (prop = props.pop()) if (prop.toLowerCase() === property.toLowerCase()) return prop; return null; } + +export function getNonFalseValuesOfPropertyInArrayOfObjects(array, propertyName) { + return (array ?? []).map((x) => x[propertyName]).filter((x) => x); +} + +export function sortArrayOfObjectsByPropertyValue(arrayOfObjects, propertyName) { + if (!arrayOfObjects) return null; + + return arrayOfObjects.sort((a, b) => { + if (a[propertyName] < b[propertyName]) return -1; + if (a[propertyName] > b[propertyName]) return 1; + return 0; + }); +} diff --git a/src/helpers/recal-helper.js b/src/helpers/recal-helper.js index f364bf68..029aee25 100644 --- a/src/helpers/recal-helper.js +++ b/src/helpers/recal-helper.js @@ -1,5 +1,5 @@ import partTypeStrings from '@/constants/part-type-strings'; -import { deepClone } from '@/helpers/object-helper'; +import { deepClone, getNonFalseValuesOfPropertyInArrayOfObjects } from '@/helpers/object-helper'; const recalPartTypes = [partTypeStrings.RECALIBRATION, partTypeStrings.ADAS_RECALIBRATION]; @@ -73,6 +73,31 @@ export function containsRecalParts(lineItems) { } } +export function isRecalOrder(lineItems) { + return (containsRecalParts(lineItems) && getHasRecalibrationPart(lineItems)); +} + +export function getHasRecalibrationPart(lineItems) { + const hasRequiresRecalibration = getNonFalseValuesOfPropertyInArrayOfObjects(lineItems.glassParts, 'requiresRecalibration')?.length > 0; + const hasRecalibrationType = getNonFalseValuesOfPropertyInArrayOfObjects(lineItems.glassParts, 'recalibrationType')?.length > 0; + + if (hasRequiresRecalibration) { + if (hasRecalibrationType) { + // Has both 'requiresRecalibration' and 'recalibrationType' and 'recalibrationType' + return ( + getNonFalseValuesOfPropertyInArrayOfObjects( + lineItems.glassParts, + 'recalibrationType' + )[0].toLowerCase() !== 'unknown' + ); + } + // Has 'requiresRecalibration' but no 'recalibrationType' at all + return true; + } + // Does not have 'requiresRecalibration' + return false; +} + export function anyPartWithRequiresRecalFlag(lineItems) { if (!lineItems) { return false; diff --git a/src/mixins/analytics-mixin.js b/src/mixins/analytics-mixin.js index b1d7d8cf..4827a559 100644 --- a/src/mixins/analytics-mixin.js +++ b/src/mixins/analytics-mixin.js @@ -21,7 +21,7 @@ import { ValueToLogTypes } from '@/constants/analytics'; import { getCartTotal, getSubtotal } from '@/helpers/cart-helper'; -import { getRecalPartNumbers } from "@/helpers/recal-helper"; +import { getRecalPartNumbers, isRecalOrder } from "@/helpers/recal-helper"; import coverageStatuses from '@/constants/coverage-statuses'; import coverageType from '@/constants/coverage-type'; import { AppointmentTypeStrings } from '@/constants/schedule-constants'; @@ -266,35 +266,12 @@ export default { payload.orderNumber = ""; } - // Pricing - // Only fire for completed orders? - - const lineItems = order.lineItems ?? {}; - const combinedLineItems = [ - ...(lineItems.glassParts ?? []), - ...(lineItems.supportingItems ?? []), - ...(lineItems.vaps ?? []), - ...(lineItems.promos ?? []), - ]; - - const isPricingAvailable = - combinedLineItems.length > 0 && - combinedLineItems.every( - (lineItem) => - isDefined(lineItem.kitPrice) && - isDefined(lineItem.laborAmount) && - isDefined(lineItem.sellingPrice) - ); - const isTaxAvailable = - isPricingAvailable && - combinedLineItems.every((lineItem) => isDefined(lineItem.salesTax)); - - //unverified (in scenarios we don’t display the price) + // Unverified (no price or deductible displayed) if (!store.isVerified) { payload.priceSubTotal = ""; + payload.priceTotal = ""; } - //deductible (in scenarios we don’t display the price) - // TODO: Need to redo this for ISS 2.0 + // Deductible case (no price is displayed, only deductible) else if ( store.isVerified && store.currentDeductible >= 0 && @@ -302,44 +279,23 @@ export default { !store.isNoComp ) { payload.priceSubTotal = ""; - } else if (isPricingAvailable) { + payload.priceTotal = ""; + // ITAC or NoComp (where cash price is shown) + } else if (store.isVerified && (store.isItac || store.isNoComp)) { const subtotal = getSubtotal(order).toFixed(2); - payload.priceSubTotal = parseFloat(subtotal); + const total = getCartTotal(order).toFixed(2); + payload.priceTotal = parseFloat(total); } else { payload.priceSubTotal = ""; + payload.priceTotal = ""; } // Cash Quote or Cash Price Sub Total payload.cashPriceSubTotal = getSubtotal(order).toString(); - //unverified (in scenarios we don’t display the price) - if (!store.isVerified) { - payload.priceTotal = ""; - } - //deductible (in scenarios we don’t display the price) - else if ( - store.isVerified && - store.currentDeductible >= 0 && - !store.isItac && - !store.isNoComp - ) { - payload.priceTotal = ""; - } else if (isTaxAvailable) { - const total = getCartTotal(order).toFixed(2); - - payload.priceTotal = parseFloat(total); - } else { - payload.priceTotal = ""; - } - // Recalibration - // TODO: Find equivalent ISS methods. - if (hasSubmittedOrder) { - payload.isRecalibrationOnOrder = store.getters.isRecalibrationOnSubmittedState; - } else { - payload.isRecalibrationOnOrder = store.hasRecalibrationPart && containsRecalParts(order.lineItems); - } + payload.isRecalibrationOnOrder = isRecalOrder(order.lineItems); // Appointment Type if (isDefined(order.serviceLocation.appointmentType)) { @@ -348,8 +304,6 @@ export default { payload.appointmentType = ""; } - //Insurance - // TODO: Find equivalent ISS methods. Using store atm need to run off order object. payload.isInsuranceVerified = store.isVerified; payload.insuranceCompanyName = store.issConfig.clientName ?? ""; if (!store.isVerified) { diff --git a/src/store/index.js b/src/store/index.js index db5894c6..a4689af7 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -22,11 +22,12 @@ import { repairWaivedForSelectedVehicle } from '@/helpers/policy-vehicle-helper'; import { buildURLSearchParams, getPartNumbersListForQueryString } from '@/helpers/querystring-helper'; -import { getRecalPartNumbers, getTopLevelGlassPartsWithRecal } from '@/helpers/recal-helper'; +import { getRecalPartNumbers, getTopLevelGlassPartsWithRecal, getHasRecalibrationPart } from '@/helpers/recal-helper'; import { getDateForSavedSessionTimeout } from '@/helpers/session-helper'; import { isMobileDevice } from '@/helpers/useragent-helper'; import issPageValues from '@/router/router-constants/issPage-values'; import CoverageStatuses from '@/constants/coverage-statuses'; +import { getNonFalseValuesOfPropertyInArrayOfObjects, sortArrayOfObjectsByPropertyValue } from '@/helpers/object-helper'; const storeId = 'main'; @@ -276,7 +277,7 @@ export const useMainStore = defineStore({ state: () => state, getters: { billToAccountNumber: (storeState) => storeState.issConfig.billToAccountNumber, - hasRecalibrationPart: (storeState) => getHasRecalibrationPart(storeState), + hasRecalibrationPart: (storeState) => getHasRecalibrationPartOnOrder(storeState), vehicle: (storeState) => storeState.order.vehicle, damage: (storeState) => storeState.order.damage, lineItems: (state) => state.order.lineItems, @@ -3179,39 +3180,8 @@ export const useMainStore = defineStore({ // Private Functions -function getHasRecalibrationPart(state) { - const hasRequiresRecalibration = getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, 'requiresRecalibration')?.length > 0; - const hasRecalibrationType = getNonFalseValuesOfPropertyInArrayOfObjects(state.order.lineItems.glassParts, 'recalibrationType')?.length > 0; - - if (hasRequiresRecalibration) { - if (hasRecalibrationType) { - // Has both 'requiresRecalibration' and 'recalibrationType' and 'recalibrationType' - return ( - getNonFalseValuesOfPropertyInArrayOfObjects( - state.order.lineItems.glassParts, - 'recalibrationType' - )[0].toLowerCase() !== 'unknown' - ); - } - // Has 'requiresRecalibration' but no 'recalibrationType' at all - return true; - } - // Does not have 'requiresRecalibration' - return false; -} - -function getNonFalseValuesOfPropertyInArrayOfObjects(array, propertyName) { - return (array ?? []).map((x) => x[propertyName]).filter((x) => x); -} - -function sortArrayOfObjectsByPropertyValue(arrayOfObjects, propertyName) { - if (!arrayOfObjects) return null; - - return arrayOfObjects.sort((a, b) => { - if (a[propertyName] < b[propertyName]) return -1; - if (a[propertyName] > b[propertyName]) return 1; - return 0; - }); +function getHasRecalibrationPartOnOrder(state) { + return getHasRecalibrationPart(state.order.lineItems); } function convertGlassPieceNamingForApi(glassArray) {