Skip to content

Commit

Permalink
fix: fix handling discount on kit subtotal only with specified quantity
Browse files Browse the repository at this point in the history
for progressive discount with additional filters
  • Loading branch information
leomp12 authored Jan 17, 2025
1 parent d34b0cf commit 1a74a7d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions functions/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,15 @@ const getValidDiscountRules = (discountRules, params, itemsForKit) => {
})
} else if (rule.discount_kit_subtotal) {
value = 0
let totalQuantity = 0
itemsForKit.forEach(item => {
const price = ecomUtils.price(item)
if (price > 0 && checkProductId(item)) {
value += price * item.quantity
totalQuantity += item.quantity
}
})
if (rule.min_quantity > 1) {
const totalQuantity = itemsForKit.reduce((acc, item) => {
return item.quantity + acc
}, 0)
if (totalQuantity > rule.min_quantity) {
value *= (rule.min_quantity / totalQuantity)
}
Expand Down

0 comments on commit 1a74a7d

Please sign in to comment.