From 2bcf9785e7f4c9df451fb86da988d51179601c70 Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Mon, 18 Dec 2023 06:50:48 -0500 Subject: [PATCH 1/3] Changed to use wipers already on the order as available wipers so that if the zip changes it doesn't matter --- src/layouts/payment-method/payment-method.vue | 77 +++++++++++-------- .../promo-modal-question.vue | 9 ++- 2 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/layouts/payment-method/payment-method.vue b/src/layouts/payment-method/payment-method.vue index 568ef5b20..718573c87 100644 --- a/src/layouts/payment-method/payment-method.vue +++ b/src/layouts/payment-method/payment-method.vue @@ -123,14 +123,28 @@ export default { // Call APIs const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage); - const wipersPromise = baseMixin.methods.dispatchStoreActionWithLogging( - storeActions.GET_WIPERS, - { - serviceZipCode: store.getters.order.serviceLocation.zipCode, - carId: store.getters.vehicle.carId, - }, - "payment-method" - ); + const lineItemsFromStore = deepClone(store.getters.order.lineItems); + const frontWipersOnOrder = + lineItemsFromStore.vaps.filter( + (wiper) => wiper.partType == partTypeStrings.FRONT_WIPER + ) ?? []; + const rearWipersOnOrder = + lineItemsFromStore.vaps.filter( + (wiper) => wiper.partType == partTypeStrings.REAR_WIPER + ) ?? []; + const orderHasFrontWipers = frontWipersOnOrder.length > 0; + const orderHasRearWipers = rearWipersOnOrder.length > 0; + + const wipersPromise = orderHasFrontWipers + ? baseMixin.methods.dispatchStoreActionWithLogging( + storeActions.GET_WIPERS, + { + serviceZipCode: store.getters.order.serviceLocation.zipCode, + carId: store.getters.vehicle.carId, + }, + "payment-method" + ) + : Promise.resolve([]); const rainDefensePromise = baseMixin.methods.dispatchStoreActionWithLogging( storeActions.GET_RAIN_DEFENSE, @@ -154,19 +168,36 @@ export default { ]; const resultMap = await settleAllPromises(promiseResultMap); - const lineItemsFromStore = deepClone(store.getters.order.lineItems); + const glassParts = lineItemsFromStore.glassParts ?? []; const supportingItems = lineItemsFromStore.supportingItems ?? []; const vaps = lineItemsFromStore.vaps ?? []; + // if the order already has wipers on it from the quote page, use those as the available wipers + // instead of what comes from the backend. This is to prevent issues with part interchange. + const availableFrontWipers = orderHasFrontWipers + ? frontWipersOnOrder + : resultMap.wipers.filter((wiper) => wiper.partType == partTypeStrings.FRONT_WIPER) ?? + []; + const availableRearWipers = orderHasRearWipers + ? rearWipersOnOrder + : resultMap.wipers.filter((wiper) => wiper.partType == partTypeStrings.REAR_WIPER) ?? + []; + const lineItemsToTax = [ resultMap.rainDefense, ...supportingItems, - ...resultMap.wipers, + ...availableFrontWipers, + ...availableRearWipers, ...glassParts, ...vaps, ]; - const availableVaps = [resultMap.rainDefense, ...resultMap.wipers]; + + const availableVaps = [ + resultMap.rainDefense, + ...availableFrontWipers, + ...availableRearWipers, + ]; const pricedLineItemsToTax = await baseMixin.methods.dispatchStoreActionWithLogging( storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA, @@ -381,36 +412,19 @@ export default { ); } - // Because we don't yet have a robust solution for part interchange ... - // if there are front wiper line items in the revalidate response, we need to delete any existing front wiper line items from the store - // and replace them with those that come back from revalidation. - const revalidateResponseHasFrontWiperLineItems = - revalidatePromoResponse.promoLineItems.find( - (lineItem) => lineItem.partType == partTypeStrings.FRONT_WIPER - ).length > 0; - - if (revalidateResponseHasFrontWiperLineItems) { - const frontWiperLineItemsInStore = this.lineItems.vaps.find( - (lineItem) => lineItem.partType == partTypeStrings.FRONT_WIPER - ); - if (frontWiperLineItemsInStore.length > 0) { - this.lineItems.vaps = this.lineItems.vaps.find( - (lineItem) => lineItem.partType != partTypeStrings.FRONT_WIPER - ); - } - } - const vapsToAddToCart = getVapsThatNeedToBeAddedToSatisfyPromos( revalidatePromoResponse.promoLineItems, this.availableVaps, this.lineItems ); + this.lineItems.vaps.push(...vapsToAddToCart); this.lineItems.promos = revalidatePromoResponse.promoLineItems; this.inactivePromos = revalidatePromoResponse.errors.map((x) => getPromoCodeWithoutBundleIdentifier(x.promoCode) ); + this.$refs.loadingModal.hideModal(); }, backButtonAction() { @@ -547,13 +561,16 @@ export default { ) { return; } + if (oldValue.promos.length < newValue.promos.length) { const oldPromoCodes = oldValue.promos.map( (promoObject) => promoObject.promoCode ); + const newlyActivatedPromoCodes = newValue.promos.filter( (newPromo) => !oldPromoCodes.includes(newPromo.promoCode) ); + const alert = createPromoSuccessAlert(newlyActivatedPromoCodes[0].promoCode); this.$refs.funnelHeader.pushGlobalAlert(alert, alert.shouldAutoFade); } else if ( diff --git a/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue b/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue index cff6ca742..64d239868 100644 --- a/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue +++ b/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue @@ -79,6 +79,8 @@ import baseMixin from "@/mixins/base-mixin.js"; import { cartItemCategories } from "@/constants/cart-item-categories"; import store from "@/store"; import { mapTaxedLineItemsToStoreFormat } from "@/store"; + +import { partTypeStrings } from "@/constants/part-type-strings"; export default { name: "promo-modal-question", @@ -253,7 +255,7 @@ export default { this.availableVaps, "payment-method" ); - + console.log(promoCodeData); if (promoCodeData.isValid) { const pricedLineItemsToTax = []; pricedLineItemsToTax.push(...promoCodeData.promoCode); @@ -272,19 +274,22 @@ export default { "payment-method", false ); + // Match all line items to the line items as they are in the store // and rebuild the original structure. + console.log(this.lineItems.vaps); this.lineItems = mapTaxedLineItemsToStoreFormat(taxedLineItems, this.lineItems); const taxedVaps = mapTaxedLineItemsToStoreFormat( taxedLineItems, this.availableVaps ); - + console.log(this.lineItems.vaps); const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos( promoCodeData.promoCode, taxedVaps, this.lineItems ); + this.lineItems?.promos.push(...promoCodeData.promoCode); this.lineItems.vaps?.push(...getVaps); this.closeModal(); From 9783c582ebe75e5a706086eab38d95031a4af1e1 Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Tue, 19 Dec 2023 07:34:47 -0500 Subject: [PATCH 2/3] Removed console logs --- .../promo-modal-question/promo-modal-question.vue | 5 ++--- src/store/index.js | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue b/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue index 64d239868..27fece310 100644 --- a/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue +++ b/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue @@ -255,7 +255,7 @@ export default { this.availableVaps, "payment-method" ); - console.log(promoCodeData); + if (promoCodeData.isValid) { const pricedLineItemsToTax = []; pricedLineItemsToTax.push(...promoCodeData.promoCode); @@ -277,13 +277,12 @@ export default { // Match all line items to the line items as they are in the store // and rebuild the original structure. - console.log(this.lineItems.vaps); this.lineItems = mapTaxedLineItemsToStoreFormat(taxedLineItems, this.lineItems); const taxedVaps = mapTaxedLineItemsToStoreFormat( taxedLineItems, this.availableVaps ); - console.log(this.lineItems.vaps); + const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos( promoCodeData.promoCode, taxedVaps, diff --git a/src/store/index.js b/src/store/index.js index 673c4dfa1..83186d527 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -2641,7 +2641,7 @@ function convertGlassPieceNamingFromApi(glassArray) { function addPricesToLineItems(lineItems, pricingLineItems) { lineItems.forEach((lineItem) => { - let lineItemIndex = pricingLineItems.findIndex( + const lineItemIndex = pricingLineItems.findIndex( (pricingLineItem) => pricingLineItem.partNumber === lineItem.partNumber ); @@ -2649,7 +2649,7 @@ function addPricesToLineItems(lineItems, pricingLineItems) { addPricesToLineItems(lineItem.childParts, pricingLineItems); } - let pricedLineItem = pricingLineItems.splice(lineItemIndex, 1)[0]; + const pricedLineItem = pricingLineItems.splice(lineItemIndex, 1)[0]; lineItem.laborAmount = pricedLineItem.laborAmount; lineItem.sellingPrice = pricedLineItem.sellingPrice; lineItem.kitPrice = pricedLineItem.kitPrice; From cc4be3a36b78665b4026cf3e20e781239aa60db4 Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Tue, 19 Dec 2023 07:37:56 -0500 Subject: [PATCH 3/3] Prettified --- .../promo-modal-question/promo-modal-question.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue b/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue index 27fece310..b4b02b3ed 100644 --- a/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue +++ b/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue @@ -282,7 +282,7 @@ export default { taxedLineItems, this.availableVaps ); - + const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos( promoCodeData.promoCode, taxedVaps,