Merge pull request #1517 from Safelite/feature/skiener/CSR-1452
CSR-1452 | Inactive promos bug fix, related refactoring
This commit is contained in:
commit
7ef6c91177
2 changed files with 30 additions and 22 deletions
|
|
@ -246,6 +246,20 @@ export function getVapsThatNeedToBeAddedToSatisfyPromos(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function removeCurrentlyActivePromoCodesFromInactivePromos(
|
||||||
|
activePromoObjects,
|
||||||
|
inactivePromos
|
||||||
|
) {
|
||||||
|
activePromoObjects = activePromoObjects ?? [];
|
||||||
|
inactivePromos = inactivePromos ?? [];
|
||||||
|
const activePromoCodes = activePromoObjects.map((promoObject) =>
|
||||||
|
getPromoCodeWithoutBundleIdentifier(promoObject.promoCode).toUpperCase()
|
||||||
|
);
|
||||||
|
return inactivePromos.filter((inactivePromo) => {
|
||||||
|
return !activePromoCodes.includes(inactivePromo.toUpperCase());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// bundle promos look like: "bundlePromo/###"" for each promo, this returns "bundlePromo" only
|
// bundle promos look like: "bundlePromo/###"" for each promo, this returns "bundlePromo" only
|
||||||
export function getPromoCodeWithoutBundleIdentifier(promoCode) {
|
export function getPromoCodeWithoutBundleIdentifier(promoCode) {
|
||||||
return promoCode.split("/")[0];
|
return promoCode.split("/")[0];
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,10 @@ import {
|
||||||
getDisplayTextForDurationLength,
|
getDisplayTextForDurationLength,
|
||||||
} from "@/layouts/schedule/helpers/schedule-helper";
|
} from "@/layouts/schedule/helpers/schedule-helper";
|
||||||
import { paymentMethods } from "@/constants/payment-method-constants";
|
import { paymentMethods } from "@/constants/payment-method-constants";
|
||||||
import { getPromoCodeWithoutBundleIdentifier } from "@/helpers/promotions-helper";
|
import {
|
||||||
|
getPromoCodeWithoutBundleIdentifier,
|
||||||
|
removeCurrentlyActivePromoCodesFromInactivePromos,
|
||||||
|
} from "@/helpers/promotions-helper";
|
||||||
import { getDateDifferenceInDays } from "@/helpers/date-helper";
|
import { getDateDifferenceInDays } from "@/helpers/date-helper";
|
||||||
// Export State
|
// Export State
|
||||||
const getDefaultState = () => {
|
const getDefaultState = () => {
|
||||||
|
|
@ -2120,14 +2123,6 @@ export const actions = {
|
||||||
addGuidToLineItemsIfNotAlreadyThere(vaps);
|
addGuidToLineItemsIfNotAlreadyThere(vaps);
|
||||||
context.commit(storeMutations.UPDATE_VAPS, vaps);
|
context.commit(storeMutations.UPDATE_VAPS, vaps);
|
||||||
},
|
},
|
||||||
// COMBINE THESE
|
|
||||||
savePromos(context, promos) {
|
|
||||||
addGuidToLineItemsIfNotAlreadyThere(promos);
|
|
||||||
context.commit(storeMutations.UPDATE_PROMOS, promos);
|
|
||||||
},
|
|
||||||
saveInactivePromos(context, inactivePromos) {
|
|
||||||
context.commit(storeMutations.UPDATE_INACTIVE_PROMOS, inactivePromos);
|
|
||||||
},
|
|
||||||
// Manage promo saving to ensure a promoCode never ends up in both active and inactive
|
// Manage promo saving to ensure a promoCode never ends up in both active and inactive
|
||||||
saveActiveAndOrInactivePromos(context, { activePromos = null, inactivePromos = null }) {
|
saveActiveAndOrInactivePromos(context, { activePromos = null, inactivePromos = null }) {
|
||||||
let activePromosToSave;
|
let activePromosToSave;
|
||||||
|
|
@ -2139,12 +2134,10 @@ export const actions = {
|
||||||
} else if (activePromos && inactivePromos) {
|
} else if (activePromos && inactivePromos) {
|
||||||
// Prioritize active promos when both inactive and active are supplied
|
// Prioritize active promos when both inactive and active are supplied
|
||||||
activePromosToSave = activePromos;
|
activePromosToSave = activePromos;
|
||||||
const activePromoCodes = activePromos.map((promoObject) =>
|
inactivePromosToSave = removeCurrentlyActivePromoCodesFromInactivePromos(
|
||||||
getPromoCodeWithoutBundleIdentifier(promoObject.promoCode)
|
activePromosToSave,
|
||||||
|
inactivePromos
|
||||||
);
|
);
|
||||||
inactivePromosToSave = inactivePromos.filter((inactivePromo) => {
|
|
||||||
return !activePromoCodes.includes(inactivePromo);
|
|
||||||
});
|
|
||||||
} else if (!activePromos) {
|
} else if (!activePromos) {
|
||||||
// Only inactivePromos supplied
|
// Only inactivePromos supplied
|
||||||
inactivePromosToSave = inactivePromos;
|
inactivePromosToSave = inactivePromos;
|
||||||
|
|
@ -2156,13 +2149,9 @@ export const actions = {
|
||||||
} else if (!inactivePromos) {
|
} else if (!inactivePromos) {
|
||||||
// Only activePromos supplied
|
// Only activePromos supplied
|
||||||
activePromosToSave = activePromos;
|
activePromosToSave = activePromos;
|
||||||
const activePromoCodes = activePromos.map((promoObject) =>
|
inactivePromosToSave = removeCurrentlyActivePromoCodesFromInactivePromos(
|
||||||
getPromoCodeWithoutBundleIdentifier(promoObject.promoCode)
|
activePromosToSave,
|
||||||
);
|
context.getters.payment.inactivePromos ?? []
|
||||||
inactivePromosToSave = (context.getters.payment.inactivePromos ?? []).filter(
|
|
||||||
(inactivePromo) => {
|
|
||||||
return !activePromoCodes.includes(inactivePromo);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
context.commit(storeMutations.UPDATE_PROMOS, activePromosToSave);
|
context.commit(storeMutations.UPDATE_PROMOS, activePromosToSave);
|
||||||
|
|
@ -2361,10 +2350,15 @@ export const actions = {
|
||||||
const order = context.getters.order;
|
const order = context.getters.order;
|
||||||
|
|
||||||
activePromosToUse = activePromosToUse ?? order.lineItems.promos;
|
activePromosToUse = activePromosToUse ?? order.lineItems.promos;
|
||||||
inactivePromosToUse = inactivePromosToUse ?? order.payment.inactivePromos;
|
|
||||||
lineItemsToUse = lineItemsToUse ? deepClone(lineItemsToUse) : deepClone(order.lineItems);
|
lineItemsToUse = lineItemsToUse ? deepClone(lineItemsToUse) : deepClone(order.lineItems);
|
||||||
lineItemsToUse.promos = activePromosToUse;
|
lineItemsToUse.promos = activePromosToUse;
|
||||||
|
|
||||||
|
inactivePromosToUse = inactivePromosToUse ?? order.payment.inactivePromos;
|
||||||
|
inactivePromosToUse = removeCurrentlyActivePromoCodesFromInactivePromos(
|
||||||
|
lineItemsToUse.promos,
|
||||||
|
inactivePromosToUse
|
||||||
|
);
|
||||||
|
|
||||||
let requestObject = {
|
let requestObject = {
|
||||||
inactivePromos: inactivePromosToUse,
|
inactivePromos: inactivePromosToUse,
|
||||||
order: {
|
order: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue