Skip to content

Commit

Permalink
fix: prefer matching discount rule with validated items when some are…
Browse files Browse the repository at this point in the history
… not

prevents wrong return of "No promotion products..." when other discount rule is available
  • Loading branch information
leomp12 committed Aug 10, 2024
1 parent aa59676 commit 3465eb3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion functions/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ const getValidDiscountRules = (discountRules, params, itemsForKit) => {
return []
}

const matchDiscountRule = (discountRules, params = {}, skipApplyAt) => {
const matchDiscountRule = (_discountRules, params = {}, skipApplyAt) => {
const validItemsDiscountRules = _discountRules.filter((rule) => {
return mapCampaignProducts(rule, params).valid
})
const discountRules = validItemsDiscountRules.length
? validItemsDiscountRules
: _discountRules
const filteredRules = skipApplyAt
? discountRules.filter((rule) => {
const applyAt = (rule.discount && rule.discount.apply_at) || 'total'
Expand Down

0 comments on commit 3465eb3

Please sign in to comment.