Rule-Based Bonus Product Promotions Enhancement - #3432
Merged
sf-cboscenco merged 2 commits intoOct 24, 2025
Conversation
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
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
ddiazccrz
approved these changes
Oct 24, 2025
| { | ||
| enabled: enabled && Boolean(promotionId) | ||
| } | ||
| ) |
Contributor
There was a problem hiding this comment.
@sf-cboscenco When is this API going to be called ?
Looks like inside useBasketProductsWithPromotions, Every time Get basket call happens ?
Contributor
There was a problem hiding this comment.
Isn't it too expensive ?
The other ProductSearch API call happens only when modal is opened I think ? @sf-shikhar-prasoon correct me.
sf-deepali-bharmal
approved these changes
Oct 24, 2025
sf-cboscenco
merged commit Oct 24, 2025
3fc3865
into
feature/bonus-products-rule-based-v3
14 of 16 checks passed
Contributor
|
Discussed implications of adding a new productSearch query internally. Looks like thats the only way around for now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
New Hook: useRuleBasedQualifyingProducts
Enhanced Promotion Eligibility Logic
Qualifying Products Map Integration
Updated Function Signatures
Component Updates
Comprehensive Test Updates
Backward Compatibility:
Description
Types of Changes
Changes
How to Test-Drive This PR
Checklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization