Skip to content

@W-19718906 bug: duplicate bonus products when store pickup for same product#3348

Merged
sf-shikhar-prasoon merged 5 commits into3.13.0-preview.5from
t/cc-sharks/sprasoon/W-19718906/releaseBugFix_storePickup/main
Sep 24, 2025
Merged

@W-19718906 bug: duplicate bonus products when store pickup for same product#3348
sf-shikhar-prasoon merged 5 commits into3.13.0-preview.5from
t/cc-sharks/sprasoon/W-19718906/releaseBugFix_storePickup/main

Conversation

@sf-shikhar-prasoon
Copy link
Contributor

@sf-shikhar-prasoon sf-shikhar-prasoon commented Sep 23, 2025

Description

This is to fix a bug where Bonus products showing up twice if the same product is added as store pickup

The bug was discovered by Jainam first (slack thread)

Please refer to the slack thread or work item for a video demo of the bug.

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

Our Solution: Capacity-Based Sequential Allocation

We implemented a sophisticated distribution system that:

  1. Calculates individual item capacity based on promotion rules and item quantities
  2. Distributes bonus products proportionally across qualifying cart items
  3. Uses first-come-first-served allocation based on cart item position
  4. Prevents duplication by tracking which bonus products have been allocated

Key Features Implemented

New Distribution Function: getBonusProductsForSpecificCartItem()

  • Handles capacity calculation per cart item
  • Allocates bonus products sequentially across qualifying items
  • Respects promotion capacity limits

Updated Cart Display: Modified CartProductListWithGroupedBonusProducts

  • Uses new distribution function instead of global product lookup
  • Maintains existing "Select Bonus Products" button behavior

Comprehensive Testing: Added 6 new test scenarios covering:

  • Equal distribution (2 suits, 4 ties → 2+2)
  • Unequal distribution (2 suits, 3 ties → 2+1)
  • Quantity multipliers (suit qty=2 gets 4 ties capacity)
  • Single item edge cases
  • Empty cart scenarios

Expected Results

  • Cart: 2 suits, 3 ties → Suit A: 2 ties, Suit B: 1 tie + "Select Bonus Products" button
  • Cart: 2 suits, 4 ties → Suit A: 2 ties, Suit B: 2 ties (no buttons needed)
  • Cart: 4 suits, 4 ties → Suit A (qty=2): 2-3 ties, Suit B (qty=2): 1-2 ties + buttons as needed

The implementation preserves all existing functionality while correctly distributing bonus products across cart items to eliminate the duplication
bug. Global capacity calculations remain accurate for button text display.

How to Test-Drive This PR

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

@sf-shikhar-prasoon sf-shikhar-prasoon requested review from a team, ddiazccrz and shethj September 23, 2025 22:33
@sf-shikhar-prasoon sf-shikhar-prasoon added ready for review PR is ready to be reviewed skip changelog Skip the "Changelog Check" GitHub Actions step even if the Changelog.md files are not updated labels Sep 23, 2025
@sf-shikhar-prasoon sf-shikhar-prasoon marked this pull request as ready for review September 23, 2025 22:33
@cc-prodsec
Copy link
Collaborator

cc-prodsec commented Sep 23, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

Copy link
Contributor

@shethj shethj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@shethj shethj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shethj shethj self-requested a review September 23, 2025 23:03
@sf-shikhar-prasoon sf-shikhar-prasoon merged commit 83f3c90 into 3.13.0-preview.5 Sep 24, 2025
42 checks passed
@sf-shikhar-prasoon sf-shikhar-prasoon deleted the t/cc-sharks/sprasoon/W-19718906/releaseBugFix_storePickup/main branch September 24, 2025 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review PR is ready to be reviewed skip changelog Skip the "Changelog Check" GitHub Actions step even if the Changelog.md files are not updated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants