CSR-1452 | Inactive promos bug fix, related refactoring
Created a shared "removeCurrentlyActivePromoCodesFromInactivePromos" method and used it in multiple places to fix bug
This commit is contained in:
parent
6058dbe16e
commit
0a9e59bf22
2 changed files with 18 additions and 24 deletions
|
|
@ -246,6 +246,17 @@ 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,8 @@ 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 +2121,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 +2132,7 @@ 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(activePromosToSave, inactivePromos);
|
||||||
getPromoCodeWithoutBundleIdentifier(promoObject.promoCode)
|
|
||||||
);
|
|
||||||
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,14 +2144,7 @@ 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(activePromosToSave, context.getters.payment.inactivePromos ?? [])
|
||||||
getPromoCodeWithoutBundleIdentifier(promoObject.promoCode)
|
|
||||||
);
|
|
||||||
inactivePromosToSave = (context.getters.payment.inactivePromos ?? []).filter(
|
|
||||||
(inactivePromo) => {
|
|
||||||
return !activePromoCodes.includes(inactivePromo);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
context.commit(storeMutations.UPDATE_PROMOS, activePromosToSave);
|
context.commit(storeMutations.UPDATE_PROMOS, activePromosToSave);
|
||||||
context.commit(storeMutations.UPDATE_INACTIVE_PROMOS, inactivePromosToSave);
|
context.commit(storeMutations.UPDATE_INACTIVE_PROMOS, inactivePromosToSave);
|
||||||
|
|
@ -2361,10 +2342,12 @@ 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