Merge pull request #1577 from Safelite/feature/skiener/CSR-1841

CSR-1841 | Change query string promo logic for save quote email purposes
This commit is contained in:
scottkiener 2023-11-28 10:32:46 -05:00 committed by GitHub
commit 5b245b94c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 17 deletions

View file

@ -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)) {

View file

@ -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) {

View file

@ -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) {