Merge pull request #1581 from Safelite/feature/skiener/CSR-1845
CSR-1845 | Fix quote pricing with bundle promos
This commit is contained in:
commit
5d83ec6e65
1 changed files with 18 additions and 1 deletions
|
|
@ -213,16 +213,33 @@ export function buildToastMessagesFromRevalidateOrValidatePromoResponse(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPromosThatMatchLineItemsOnOrder(promos, lineItemsOnOrder) {
|
export function getPromosThatMatchLineItemsOnOrder(promos, lineItemsOnOrder) {
|
||||||
|
const matchingPromoCodes = [];
|
||||||
const matchingPromos = [];
|
const matchingPromos = [];
|
||||||
|
const consolidatedPromosWithIds = {};
|
||||||
|
// Combine bundle promos to make sure each part of the bundle is satisfied
|
||||||
promos.forEach((promo) => {
|
promos.forEach((promo) => {
|
||||||
|
const cleanPromoCode = getPromoCodeWithoutBundleIdentifier(promo.promoCode);
|
||||||
|
if (consolidatedPromosWithIds[cleanPromoCode]) {
|
||||||
|
consolidatedPromosWithIds[cleanPromoCode].push(...promo.discountedLineItemIds);
|
||||||
|
} else {
|
||||||
|
consolidatedPromosWithIds[cleanPromoCode] = promo.discountedLineItemIds.slice(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Object.keys(consolidatedPromosWithIds).forEach((promoCode) => {
|
||||||
let allIdsMatch = true;
|
let allIdsMatch = true;
|
||||||
promo.discountedLineItemIds.forEach((id) => {
|
consolidatedPromosWithIds[promoCode].forEach((id) => {
|
||||||
if (lineItemsOnOrder.filter((x) => x.id === id).length === 0) {
|
if (lineItemsOnOrder.filter((x) => x.id === id).length === 0) {
|
||||||
allIdsMatch = false;
|
allIdsMatch = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (allIdsMatch) {
|
if (allIdsMatch) {
|
||||||
|
matchingPromoCodes.push(promoCode);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
promos.forEach((promo) => {
|
||||||
|
const cleanPromoCode = getPromoCodeWithoutBundleIdentifier(promo.promoCode);
|
||||||
|
if (matchingPromoCodes.includes(cleanPromoCode)) {
|
||||||
matchingPromos.push(promo);
|
matchingPromos.push(promo);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue