Skip to content

Fix kit discounts incorrectly applying to freebie items#704

Open
vitorrgg wants to merge 1 commit intomainfrom
itemsForkit
Open

Fix kit discounts incorrectly applying to freebie items#704
vitorrgg wants to merge 1 commit intomainfrom
itemsForkit

Conversation

@vitorrgg
Copy link
Member

No description provided.

@vitorrgg
Copy link
Member Author

@claude review

@claude
Copy link

claude bot commented Feb 27, 2026

Claude finished @vitorrgg's task in 42s —— View job


Code Review

  • Gather context
  • Read changed file and diff
  • Analyze the changes
  • Post review feedback

Summary

This PR fixes a logical inconsistency in the kit discount logic inside apply-discount.mjs. The fix is small, correct, and well-scoped.


Analysis

The Bug

itemsForKit was already defined earlier in the function (lines 283–285) to exclude freebie items:

const itemsForKit = params.items.filter((item) => {
  return !item.flags?.includes('freebie');
});

This filtered list was correctly passed to getValidDiscountRules (line 286–290) to determine which discount rules apply. However, inside the discount loop, when building kitItems (the actual items the discount gets applied to), the code was reverting back to params.items instead of itemsForKit. This meant freebie items could slip into kitItems and have a discount incorrectly applied to them.

The Fix

All three kitItems assignment branches now use itemsForKit:

Case Before After
Filter by product_ids params.items.filter(...) itemsForKit.filter(...)
Filter by category_ids params.items.filter(...) itemsForKit.filter(...)
No filter (catch-all) [...params.items] [...itemsForKit]

Assessment

  • The fix is correct. It closes the gap between how discount rules are validated (using itemsForKit) and how discounted items are selected (now also using itemsForKit).
  • The change is consistent — all three branches are updated, preventing any path from re-introducing freebie items.
  • The recommendBuyTogether logic (line 348+) still uses params.items directly, which is intentional — buy-together recommendations should consider the full cart, not just non-freebie items. This is unaffected and correct.
  • No new variables, abstractions, or risky changes are introduced.

No issues found. The PR is clean and the fix is minimal and appropriate.


@vitorrgg vitorrgg requested a review from leomp12 February 27, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant