Skip to content

Rule-Based Bonus Product Promotions Enhancement - #3432

Merged
sf-cboscenco merged 2 commits into
feature/bonus-products-rule-based-v3from
t/cc-sharks/W-20037720
Oct 24, 2025
Merged

Rule-Based Bonus Product Promotions Enhancement#3432
sf-cboscenco merged 2 commits into
feature/bonus-products-rule-based-v3from
t/cc-sharks/W-20037720

Conversation

@sf-cboscenco

@sf-cboscenco sf-cboscenco commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

This PR enhances the existing rule-based bonus product promotions feature by adding proper variant eligibility checking. Previously, rule-based promotions could not accurately determine which specific product variants qualified for a promotion. This enhancement introduces a qualifying products lookup system that uses the product search API to fetch and validate eligible variants, ensuring that only products that truly qualify can trigger bonus product selection UI and functionality.

Key Changes:

  1. New Hook: useRuleBasedQualifyingProducts

    • Added to app/hooks/use-rule-based-bonus-products.js
    • Fetches qualifying products for rule-based promotions using productSearch API
    • Uses refinement parameters: pmid=${promotionId} and pmpt=qualifying
    • Returns a Set of qualifying product IDs for efficient lookup
    • Supports variant eligibility checking by examining both variant and master product IDs
  2. Enhanced Promotion Eligibility Logic

    • Updated getPromotionIdsForProduct() in app/utils/bonus-product/common.js
    • Distinguishes between list-based and rule-based promotions
    • Added fallback logic to check master product IDs when variants don't directly qualify
    • Filters promotion IDs to only return those the product actually qualifies for
  3. Qualifying Products Map Integration

    • Added ruleBasedQualifyingProductsMap parameter throughout the bonus product utility chain
    • Updated useBasketProductsWithPromotions() hook to fetch and return qualifying products map
    • Propagated the map through all relevant functions and components
  4. Updated Function Signatures

    • isAutomaticPromotion()
    • shouldShowBonusProductSelection()
    • getBonusProductsForSpecificCartItem()
    • getBonusProductsInCartForProduct()
    • getAvailableBonusItemsForProduct()
    • getRemainingAvailableBonusProductsForProduct()
  5. Component Updates

    • Cart Page: Destructures and passes ruleBasedQualifyingProductsMap
    • Add to Cart Modal: Uses qualifying products map for eligibility checks
    • Cart Product List: Accepts and forwards ruleBasedQualifyingProductsMap prop
  6. Comprehensive Test Updates

    • Updated all test files to distinguish list-based vs rule-based promotions
    • Added new test cases for rule-based promotion eligibility scenarios
    • Enhanced test coverage across all bonus product utility test files

Backward Compatibility:

  • All changes are backward compatible with existing list-based promotions
  • Default parameter values ensure functions work without the new map
  • Existing tests updated to explicitly mark promotions as list-based

Description

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

  • (change1)

How to Test-Drive This PR

  • (step1)

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)

This PR enhances the existing rule-based bonus product promotions feature by adding proper variant eligibility checking. Previously, rule-based promotions could not accurately determine which specific product variants qualified for a promotion. This enhancement introduces a qualifying products lookup system that uses the product search API to fetch and validate eligible variants, ensuring that only products that truly qualify can trigger bonus product selection UI and functionality.

Key Changes:

1. New Hook: useRuleBasedQualifyingProducts
   - Added to app/hooks/use-rule-based-bonus-products.js
   - Fetches qualifying products for rule-based promotions using productSearch API
   - Uses refinement parameters: pmid=${promotionId} and pmpt=qualifying
   - Returns a Set of qualifying product IDs for efficient lookup
   - Supports variant eligibility checking by examining both variant and master product IDs

2. Enhanced Promotion Eligibility Logic
   - Updated getPromotionIdsForProduct() in app/utils/bonus-product/common.js
   - Distinguishes between list-based and rule-based promotions
   - Added fallback logic to check master product IDs when variants don't directly qualify
   - Filters promotion IDs to only return those the product actually qualifies for

3. Qualifying Products Map Integration
   - Added ruleBasedQualifyingProductsMap parameter throughout the bonus product utility chain
   - Updated useBasketProductsWithPromotions() hook to fetch and return qualifying products map
   - Propagated the map through all relevant functions and components

4. Updated Function Signatures
   - isAutomaticPromotion()
   - shouldShowBonusProductSelection()
   - getBonusProductsForSpecificCartItem()
   - getBonusProductsInCartForProduct()
   - getAvailableBonusItemsForProduct()
   - getRemainingAvailableBonusProductsForProduct()

5. Component Updates
   - Cart Page: Destructures and passes ruleBasedQualifyingProductsMap
   - Add to Cart Modal: Uses qualifying products map for eligibility checks
   - Cart Product List: Accepts and forwards ruleBasedQualifyingProductsMap prop

6. Comprehensive Test Updates
   - Updated all test files to distinguish list-based vs rule-based promotions
   - Added new test cases for rule-based promotion eligibility scenarios
   - Enhanced test coverage across all bonus product utility test files

Backward Compatibility:
- All changes are backward compatible with existing list-based promotions
- Default parameter values ensure functions work without the new map
- Existing tests updated to explicitly mark promotions as list-based
@sf-cboscenco
sf-cboscenco requested a review from a team as a code owner October 24, 2025 22:12
@sf-cboscenco
sf-cboscenco requested a review from a team October 24, 2025 22:12
@cc-prodsec

cc-prodsec commented Oct 24, 2025

Copy link
Copy Markdown
Collaborator

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

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

{
enabled: enabled && Boolean(promotionId)
}
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@sf-cboscenco When is this API going to be called ?
Looks like inside useBasketProductsWithPromotions, Every time Get basket call happens ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't it too expensive ?

The other ProductSearch API call happens only when modal is opened I think ? @sf-shikhar-prasoon correct me.

@sf-cboscenco
sf-cboscenco merged commit 3fc3865 into feature/bonus-products-rule-based-v3 Oct 24, 2025
14 of 16 checks passed
@sf-cboscenco
sf-cboscenco deleted the t/cc-sharks/W-20037720 branch October 24, 2025 23:28
@sf-deepali-bharmal

Copy link
Copy Markdown
Contributor

Discussed implications of adding a new productSearch query internally. Looks like thats the only way around for now.

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.

4 participants