From f165bd41b9beb6e0211407160c8ed969b57923c0 Mon Sep 17 00:00:00 2001 From: Scott Kiener Date: Tue, 28 Nov 2023 15:10:28 -0500 Subject: [PATCH] CSR-1845 | Fix quote pricing with bundle promos --- src/helpers/promotions-helper.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/helpers/promotions-helper.js b/src/helpers/promotions-helper.js index f37a78e71..3968248d6 100644 --- a/src/helpers/promotions-helper.js +++ b/src/helpers/promotions-helper.js @@ -213,16 +213,33 @@ export function buildToastMessagesFromRevalidateOrValidatePromoResponse( } export function getPromosThatMatchLineItemsOnOrder(promos, lineItemsOnOrder) { + const matchingPromoCodes = []; const matchingPromos = []; + const consolidatedPromosWithIds = {}; + // Combine bundle promos to make sure each part of the bundle is satisfied 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; - promo.discountedLineItemIds.forEach((id) => { + consolidatedPromosWithIds[promoCode].forEach((id) => { if (lineItemsOnOrder.filter((x) => x.id === id).length === 0) { allIdsMatch = false; return; } }); if (allIdsMatch) { + matchingPromoCodes.push(promoCode); + } + }); + promos.forEach((promo) => { + const cleanPromoCode = getPromoCodeWithoutBundleIdentifier(promo.promoCode); + if (matchingPromoCodes.includes(cleanPromoCode)) { matchingPromos.push(promo); } });