From 80adf99f63dd4e307ae6cdc3e818ea9d9bcbb582 Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Thu, 9 Nov 2023 09:41:35 -0500 Subject: [PATCH 1/4] Made available line items return empty glass part, supporting items and available vaps arrays to prevent errors --- src/fmg-components/cart/cart.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fmg-components/cart/cart.vue b/src/fmg-components/cart/cart.vue index 6d709edeb..28cb25d50 100644 --- a/src/fmg-components/cart/cart.vue +++ b/src/fmg-components/cart/cart.vue @@ -177,9 +177,9 @@ export default { return []; } return [ - ...this.lineItems.glassParts, - ...this.lineItems.supportingItems, - ...this.availableVaps, + ...this.lineItems.glassParts ?? [], + ...this.lineItems.supportingItems ?? [], + ...this.availableVaps ?? [], ]; }, cartItems: { From e3887f931e2756e82eddd8c3cc7beff22b72033a Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Thu, 9 Nov 2023 09:43:58 -0500 Subject: [PATCH 2/4] Prettified --- src/fmg-components/cart/cart.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fmg-components/cart/cart.vue b/src/fmg-components/cart/cart.vue index 28cb25d50..7390495f2 100644 --- a/src/fmg-components/cart/cart.vue +++ b/src/fmg-components/cart/cart.vue @@ -177,9 +177,9 @@ export default { return []; } return [ - ...this.lineItems.glassParts ?? [], - ...this.lineItems.supportingItems ?? [], - ...this.availableVaps ?? [], + ...(this.lineItems.glassParts ?? []), + ...(this.lineItems.supportingItems ?? []), + ...(this.availableVaps ?? []), ]; }, cartItems: { From d781b7fdadb2ebffb2615c19478fa52208b28d66 Mon Sep 17 00:00:00 2001 From: Matt Caimi Date: Thu, 9 Nov 2023 10:49:24 -0500 Subject: [PATCH 3/4] CSR-1462 line items refactor fix for payment page --- src/layouts/payment/payment.vue | 53 +++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/layouts/payment/payment.vue b/src/layouts/payment/payment.vue index fa8d91676..1886d4aa0 100644 --- a/src/layouts/payment/payment.vue +++ b/src/layouts/payment/payment.vue @@ -192,9 +192,11 @@ import { mapTaxedLineItemsToStoreFormat } from "../../store"; import { revalidatePromosAndValidateNewPromo, getAddableVapsFromAvailableLineItems, + getVapsThatNeedToBeAddedToSatisfyPromos, } from "@/helpers/promotions-helper"; import { queryStrings } from "@/constants/query-strings"; import { getQuerystringParameter } from "@/helpers/querystring-helper"; +import { deepClone } from "@/helpers/object-helper"; import iframeResize from "../../../node_modules/iframe-resizer/js/iframeResizer.js"; @@ -228,7 +230,7 @@ export default { piaLineItems: this.getPiaLineItems(), paypalPayment: this.isPaypal(), lineItems: [], - availableLineItems: [], + availableVaps: [], }; }, directives: { @@ -297,22 +299,22 @@ export default { ]; const resultMap = await settleAllPromises(promiseResultMap); - - const glassParts = store.getters.order.lineItems.glassParts ?? []; - - let availableLineItems = [ + const lineItemsFromStore = deepClone(store.getters.order.lineItems); + const glassParts = lineItemsFromStore.glassParts ?? []; + const supportingItems = lineItemsFromStore.supportingItems ?? []; + + const lineItemsToTax = [ resultMap.rainDefense, - ...resultMap.supportingItems, + ...supportingItems, ...resultMap.wipers, ...glassParts, ]; + const availableVaps = [resultMap.rainDefense, ...resultMap.wipers]; - const lineItemsFromStore = store.getters.order.lineItems; - - await baseMixin.methods.dispatchStoreActionWithLogging( + const pricedLineItemsToTax = await baseMixin.methods.dispatchStoreActionWithLogging( storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA, { - availableLineItems: availableLineItems, + availableLineItems: lineItemsToTax, }, "payment", false @@ -324,14 +326,16 @@ export default { const { validatePromoResponse, revalidatePromoResponse } = await revalidatePromosAndValidateNewPromo( promoCodeFromQueryString, - availableLineItems, - "payment-method" + pricedLineItemsToTax, + "payment" ); - availableLineItems.push(...(validatePromoResponse?.orderPromos ?? [])); + const newValidatedPromos = validatePromoResponse?.orderPromos ?? []; + + pricedLineItemsToTax.push(...newValidatedPromos); // End of promo logic - const taxedAvailableLineItems = await baseMixin.methods.dispatchStoreActionWithLogging( + const taxedLineItems = await baseMixin.methods.dispatchStoreActionWithLogging( storeActions.TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA, { billToAccountNumber: "87291", @@ -340,22 +344,33 @@ export default { serviceLocationCity: store.getters.order.serviceLocation.city, serviceLocationState: store.getters.order.serviceLocation.state, serviceLocationZipCode: store.getters.order.serviceLocation.zipCode, - pricedAvailableLineItems: availableLineItems, + pricedLineItems: pricedLineItemsToTax, }, - "payment-method", + "payment", false ); - // Match all available line items to the line items as they are in the store + // Match all line items to the line items as they are in the store // and rebuild the original structure. - const lineItems = mapTaxedLineItemsToStoreFormat(availableLineItems, lineItemsFromStore); + const lineItems = mapTaxedLineItemsToStoreFormat(taxedLineItems, lineItemsFromStore); + const taxedVaps = mapTaxedLineItemsToStoreFormat(taxedLineItems, availableVaps); + + // Add items that were not in the store yet but added via query string promo validation + lineItems.promos = lineItems.promos ?? []; + lineItems.promos.push(...newValidatedPromos); + const vapsToAddToCart = getVapsThatNeedToBeAddedToSatisfyPromos( + newValidatedPromos, + taxedVaps, + lineItems + ); + lineItems.vaps.push(...vapsToAddToCart); // Call the "next" function to complete the transition to this page. next(async (vm) => { vm.setCmsContent(resultMap.cmsContent); vm.fetchSignatureInfo(resultMap.signature); - vm.availableLineItems = taxedAvailableLineItems; + vm.availableVaps = taxedVaps; vm.lineItems = lineItems; }); }, From effe8b4d8962752ced1e63e0e1efe3b801c7b3d0 Mon Sep 17 00:00:00 2001 From: Matt Caimi Date: Thu, 9 Nov 2023 10:51:33 -0500 Subject: [PATCH 4/4] formatting --- src/layouts/payment/payment.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/layouts/payment/payment.vue b/src/layouts/payment/payment.vue index 1886d4aa0..a0c75fe82 100644 --- a/src/layouts/payment/payment.vue +++ b/src/layouts/payment/payment.vue @@ -302,7 +302,7 @@ export default { const lineItemsFromStore = deepClone(store.getters.order.lineItems); const glassParts = lineItemsFromStore.glassParts ?? []; const supportingItems = lineItemsFromStore.supportingItems ?? []; - + const lineItemsToTax = [ resultMap.rainDefense, ...supportingItems, @@ -330,7 +330,7 @@ export default { "payment" ); - const newValidatedPromos = validatePromoResponse?.orderPromos ?? []; + const newValidatedPromos = validatePromoResponse?.orderPromos ?? []; pricedLineItemsToTax.push(...newValidatedPromos); // End of promo logic @@ -354,7 +354,7 @@ export default { // and rebuild the original structure. const lineItems = mapTaxedLineItemsToStoreFormat(taxedLineItems, lineItemsFromStore); const taxedVaps = mapTaxedLineItemsToStoreFormat(taxedLineItems, availableVaps); - + // Add items that were not in the store yet but added via query string promo validation lineItems.promos = lineItems.promos ?? []; lineItems.promos.push(...newValidatedPromos);