exclude active freebie items from product kit discount calculation#703
exclude active freebie items from product kit discount calculation#703
Conversation
| const itemsForKit = params.items.filter((item) => { | ||
| return !item.flags?.includes('freebie'); | ||
| }); |
There was a problem hiding this comment.
Mas você tem alguma evidência de brinde chegando sem a flag? 🤔
|
Claude finished @leomp12's task in 4m 12s —— View job Code Review — Freebie Kit Exclusion
Resposta à pergunta do @leomp12Sobre a flag Investigando o código base, os itens de brinde podem chegar em
Então sim, brindes podem chegar sem flag em Problema na implementação do PRA coleção de PR (linha 283-296): config.freebies_rules.forEach((rule) => {
if (
validateDateRange(rule)
&& validateCustomerId(rule, params)
&& Array.isArray(rule.product_ids)
&& matchFreebieRule(rule, params)
) { ... }
});
config.freebies_rules.filter((rule) => {
return validateDateRange(rule)
&& validateCustomerId(rule, params)
&& mapCampaignProducts({ product_ids: rule.check_product_ids }, params).valid // ← FALTA
&& Array.isArray(rule.product_ids)
&& rule.product_ids.length // ← FALTA
&& matchFreebieRule(rule, params);
});Dois problemas:
Solução sugerida: Alinhar as validações com |
Problem
Freebie items (added via
freebies_rules) were being included inproduct_kit_discountscalculations. For rules usingdiscount_lowest_price: trueandcheck_all_items: true, the freebie's price would become the lowest price used as the discount base, and the freebie's quantity would count toward the kit minimum — both causing the kit discount to be much lower than intended.Solution
Before processing kit discounts, collect the product IDs of currently active freebie rules (validated by date range, customer, and coupon/UTM). These IDs are then excluded from two places:
kitEligibleItems— the items array passed togetValidDiscountRules, which is used to determine the lowest price fordiscount_lowest_pricerules.kitItemsfilter — the items used to compute total quantity and apply the discount, preventing the freebie from triggering or inflating kit counts.Impact
No change in behavior when no freebie rules are active. When a freebie rule is active, only its specific product IDs are excluded from kit calculations; all other items remain unaffected.
Fixes #702