From 85b57cb4ccd10998fead4aa778f17c14f657eb8e Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Tue, 17 Sep 2024 19:06:57 -0300 Subject: [PATCH] fix: prevent priced freebies discount mismatch with wrong max discount check --- functions/routes/ecom/modules/apply-discount.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/functions/routes/ecom/modules/apply-discount.js b/functions/routes/ecom/modules/apply-discount.js index 78351e0..990d743 100644 --- a/functions/routes/ecom/modules/apply-discount.js +++ b/functions/routes/ecom/modules/apply-discount.js @@ -266,10 +266,12 @@ ${discountedSkus.map((sku) => `\n${sku}: ${discountPerSku[sku].toFixed(2)}`)} const addFreebies = () => { const { value, label } = getFreebiesPreview() if (value) { + const maxDiscount = Math.min(value, params.amount.total || 0) addDiscount( { type: 'fixed', value }, 'FREEBIES', - label + label, + maxDiscount ) } }