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
|
||||
export function getPromoCodeWithoutBundleIdentifier(promoCode) {
|
||||
return promoCode.split("/")[0];
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ import {
|
|||
getDisplayTextForDurationLength,
|
||||
} from "@/layouts/schedule/helpers/schedule-helper";
|
||||
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";
|
||||
// Export State
|
||||
const getDefaultState = () => {
|
||||
|
|
@ -2120,14 +2121,6 @@ export const actions = {
|
|||
addGuidToLineItemsIfNotAlreadyThere(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
|
||||
saveActiveAndOrInactivePromos(context, { activePromos = null, inactivePromos = null }) {
|
||||
let activePromosToSave;
|
||||
|
|
@ -2139,12 +2132,7 @@ export const actions = {
|
|||
} else if (activePromos && inactivePromos) {
|
||||
// Prioritize active promos when both inactive and active are supplied
|
||||
activePromosToSave = activePromos;
|
||||
const activePromoCodes = activePromos.map((promoObject) =>
|
||||
getPromoCodeWithoutBundleIdentifier(promoObject.promoCode)
|
||||
);
|
||||
inactivePromosToSave = inactivePromos.filter((inactivePromo) => {
|
||||
return !activePromoCodes.includes(inactivePromo);
|
||||
});
|
||||
inactivePromosToSave = removeCurrentlyActivePromoCodesFromInactivePromos(activePromosToSave, inactivePromos);
|
||||
} else if (!activePromos) {
|
||||
// Only inactivePromos supplied
|
||||
inactivePromosToSave = inactivePromos;
|
||||
|
|
@ -2156,14 +2144,7 @@ export const actions = {
|
|||
} else if (!inactivePromos) {
|
||||
// Only activePromos supplied
|
||||
activePromosToSave = activePromos;
|
||||
const activePromoCodes = activePromos.map((promoObject) =>
|
||||
getPromoCodeWithoutBundleIdentifier(promoObject.promoCode)
|
||||
);
|
||||
inactivePromosToSave = (context.getters.payment.inactivePromos ?? []).filter(
|
||||
(inactivePromo) => {
|
||||
return !activePromoCodes.includes(inactivePromo);
|
||||
}
|
||||
);
|
||||
inactivePromosToSave = removeCurrentlyActivePromoCodesFromInactivePromos(activePromosToSave, context.getters.payment.inactivePromos ?? [])
|
||||
}
|
||||
context.commit(storeMutations.UPDATE_PROMOS, activePromosToSave);
|
||||
context.commit(storeMutations.UPDATE_INACTIVE_PROMOS, inactivePromosToSave);
|
||||
|
|
@ -2361,10 +2342,12 @@ export const actions = {
|
|||
const order = context.getters.order;
|
||||
|
||||
activePromosToUse = activePromosToUse ?? order.lineItems.promos;
|
||||
inactivePromosToUse = inactivePromosToUse ?? order.payment.inactivePromos;
|
||||
lineItemsToUse = lineItemsToUse ? deepClone(lineItemsToUse) : deepClone(order.lineItems);
|
||||
lineItemsToUse.promos = activePromosToUse;
|
||||
|
||||
inactivePromosToUse = inactivePromosToUse ?? order.payment.inactivePromos;
|
||||
inactivePromosToUse = removeCurrentlyActivePromoCodesFromInactivePromos(lineItemsToUse.promos, inactivePromosToUse);
|
||||
|
||||
let requestObject = {
|
||||
inactivePromos: inactivePromosToUse,
|
||||
order: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue