Skip to content

Conversation

Copy link

Copilot AI commented Sep 24, 2025

Implements the requested bundle discount feature that allows customers to receive 10% off when purchasing all items in a product bundle.

What this PR does

This PR adds a new type of special offer - bundles - that provides discounts when customers buy complete sets of products together. When all items in a bundle are purchased, customers receive a 10% discount on the total price of those bundled items.

Key Features

  • Complete bundle discounting: Only applies discount when all products in a bundle are purchased
  • Partial bundle handling: No discount applied for incomplete bundles
  • Multiple bundle support: Correctly handles multiple complete bundles in a single transaction
  • Fractional quantity handling: Only whole items count toward bundle completion
  • Configurable discount: Default 10% discount, but customizable percentage supported

Example Usage

const catalog = new FakeCatalog();
const toothbrush = new Product("toothbrush", ProductUnit.Each);
catalog.addProduct(toothbrush, 0.99);
const toothpaste = new Product("toothpaste", ProductUnit.Each);
catalog.addProduct(toothpaste, 1.79);

const teller = new Teller(catalog);
teller.addBundleOffer([toothbrush, toothpaste]); // 10% discount on €2.78

// Customer buys 1 toothbrush + 1 toothpaste = gets €0.28 discount
// Customer buys 2 toothbrushes + 1 toothpaste = gets €0.28 discount (only 1 complete bundle)

Implementation Details

The solution introduces minimal changes while maintaining backward compatibility:

  • Added Bundle enum value to SpecialOfferType
  • Created Bundle and BundleOffer classes for bundle data structures
  • Extended Teller with addBundleOffer() method
  • Added handleBundleOffers() method to ShoppingCart for discount calculation
  • Comprehensive test suite covering all edge cases

Test Coverage

All existing tests continue to pass, plus 5 new test cases covering:

  • Complete bundle discount calculation
  • Partial bundle scenarios (no discount)
  • Multiple complete bundles
  • Excess items handling
  • Fractional quantity edge cases

The implementation exactly matches the requirements in the original Dutch issue: "Wanneer je alle items in een productbundel koopt, krijg je 10% korting op het totaalbedrag voor die items."

Fixes #19


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Feature: discounted bundles Feature: Implement discounted bundles for product combinations Sep 24, 2025
Copilot AI requested a review from nstubbe September 24, 2025 12:11
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.

Feature: discounted bundles

2 participants