diff --git a/src/helpers/promotions-helper.js b/src/helpers/promotions-helper.js index 567304de6..f37a78e71 100644 --- a/src/helpers/promotions-helper.js +++ b/src/helpers/promotions-helper.js @@ -132,8 +132,19 @@ export async function revalidatePromosAndValidateQueryStringPromo( pageNameToLog, false ); - if (!excludeFromInactivePromoErrorCodes.includes(validatePromoResponse.errorCode)) { - // Save any valid (applied or not) query string promoCode to inactivePromos + if (validatePromoResponse.errorCode == null) { + // Save promo to store + const activePromos = store.getters.order.lineItems.promos ?? []; + activePromos.push(...validatePromoResponse.orderPromos); + baseMixin.methods.dispatchStoreAction( + storeActions.SAVE_ACTIVE_AND_OR_INACTIVE_PROMOS, + { + activePromos: activePromos, + }, + false + ); + } else if (!excludeFromInactivePromoErrorCodes.includes(validatePromoResponse.errorCode)) { + // Save any valid query string promoCode (not applied) to inactivePromos // in order to not lose the query string promoCode if back button is pressed const inactivePromoCodes = store.getters.payment.inactivePromos ?? []; if (!inactivePromoCodes.includes(newPromo)) { diff --git a/src/layouts/quote/quote.vue b/src/layouts/quote/quote.vue index a07f73566..e48e8fff8 100644 --- a/src/layouts/quote/quote.vue +++ b/src/layouts/quote/quote.vue @@ -178,7 +178,6 @@ export default { vm.supportingItems = resultMap.supportingItems; vm.availableLineItems = pricingResults; vm.isInsuranceSelected = vm.getDefaultIsInsuranceSelectedValue(vm.availableLineItems); - vm.newValidatedPromos = validatePromoResponse?.orderPromos; if (revalidatePromoResponse) { const revalidateAlerts = buildToastMessagesFromRevalidateOrValidatePromoResponse( @@ -207,16 +206,11 @@ export default { availableLineItems: null, supportingItems: null, pricedGlassParts: null, - newValidatedPromos: null, }; }, computed: { allActivePromos() { - const allActivePromos = []; - if (this.newValidatedPromos) allActivePromos.push(...this.newValidatedPromos); - if (this.$store.getters.order.lineItems.promos) - allActivePromos.push(...this.$store.getters.order.lineItems.promos); - return allActivePromos; + return this.$store.getters.order.lineItems.promos ?? []; }, }, methods: { @@ -294,14 +288,6 @@ export default { } this.dispatchStoreAction(this.storeActions.SAVE_VAPS, this.selectedVaps, false); - this.dispatchStoreAction( - this.storeActions.SAVE_ACTIVE_AND_OR_INACTIVE_PROMOS, - { activePromos: this.allActivePromos }, - false - ); - // Clear out local promos to avoid duplicates in `allActivePromos` computed - // otherwise package price changes while next page is loading - this.newValidatedPromos = []; const payment = this.$store.getters.payment; if (payment.isInsurance) { diff --git a/src/store/index.js b/src/store/index.js index 332b60cf6..efaf5b428 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -2130,6 +2130,8 @@ export const actions = { }, // Manage promo saving to ensure a promoCode never ends up in both active and inactive saveActiveAndOrInactivePromos(context, { activePromos = null, inactivePromos = null }) { + activePromos = activePromos?.slice(0); + inactivePromos = inactivePromos?.slice(0); let activePromosToSave; let inactivePromosToSave; if (!activePromos && !inactivePromos) {