Skip to content

Conversation

@sf-shikhar-prasoon
Copy link
Contributor

Description

@W-19980361 Rule based bonus products- Work Item 2- update display logic

This PR is against another branch of mine so that the diff better indicates work done in this PR
once that branch's PR is merged, i'll edit this PR's base branch to point to the feature branch

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)

@sf-shikhar-prasoon sf-shikhar-prasoon requested a review from a team October 17, 2025 17:20
@sf-shikhar-prasoon sf-shikhar-prasoon added the skip changelog Skip the "Changelog Check" GitHub Actions step even if the Changelog.md files are not updated label Oct 17, 2025
@sf-shikhar-prasoon sf-shikhar-prasoon marked this pull request as ready for review October 17, 2025 17:20
@cc-prodsec
Copy link
Collaborator

cc-prodsec commented Oct 17, 2025

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.

@sf-shikhar-prasoon sf-shikhar-prasoon requested a review from a team as a code owner October 17, 2025 17:20
Base automatically changed from t/cc-sharks/W-18957985/rule-based-w1/main to feature/bonus-products-rule-based-v3 October 21, 2025 15:17
Resolved conflicts:
- app/utils/bonus-product/discovery.js: Kept refactored version with processBonusProducts helper
- app/hooks/use-bonus-product-selection-modal/use-bonus-product-data.test.js: Kept w2's additional tests for rule-based products
@sf-shikhar-prasoon sf-shikhar-prasoon merged commit cca5519 into feature/bonus-products-rule-based-v3 Oct 23, 2025
41 of 42 checks passed
@sf-shikhar-prasoon sf-shikhar-prasoon deleted the t/cc-sharks/W-19980361/rule-based-w2/main branch October 23, 2025 09:23
sf-shikhar-prasoon added a commit that referenced this pull request Oct 25, 2025
…3418)

* @W-18957985- Product Search Integration & Rule-Based Detection (#3396)

* 1. use search endpoint

* 2 add rule based detection

* 3. update discovery logic

* add tests, update bundle size limit, update changelog

* @W-19980361 Rule based bonus products- Work Item 2- update display logic (#3408)

* 1. use search endpoint

* 2 add rule based detection

* 3. update discovery logic

* cleanup. remove unused code

* add tests, update bundle size limit, update changelog

* fix header counts

* fix flasing, re-rendering

* pr comments + lint

* @W-19980361 fix 2 bugs- selection count & flashing due to re-renders (#3421)

* fix header counts

* fix flasing, re-rendering

* pr comments + lint

* add param &refine=pmpt=bonus for promotion type

* pr comments

* use commerce sdk

* add const- limit=50  |  replace harded Search Param values

* remove function breakdown change

* update changelog

* refactor. re-use

* fix: prevent promotion message flashing when changing product variant… (#3428)

* fix tests

* Rule-Based Bonus Product Promotions Enhancement

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

* fix: prevent promotion message flashing when changing product variant (#3431)

* fix: prevent promotion flash by keeping previous data during variant changes

- Add keepPreviousData option parameter to useProductViewModal hook
- Pass keepPreviousData: true in BonusProductViewModal to maintain UI stability
- Prevents promotion message from clearing while fetching new variant data

* chore: trigger CI

* remove those stable references

* revert last changes

* bundle size limit update

* @W-20037720: Not allow duplicate items to appear in the cart (#3433)

* Fixed duplicating bonus products in the UI

* Fixed issue with list based not rendering properly

* Update cart-product-list-with-grouped-bonus-products.jsx

Signed-off-by: Daniel Diaz <[email protected]>

* Fixed lint errors

---------

Signed-off-by: Daniel Diaz <[email protected]>

---------

Signed-off-by: Daniel Diaz <[email protected]>
Co-authored-by: sf-xingquan-jin <[email protected]>
Co-authored-by: cboscenco <[email protected]>
Co-authored-by: Daniel Diaz <[email protected]>
shethj pushed a commit that referenced this pull request Oct 31, 2025
…3418)

* @W-18957985- Product Search Integration & Rule-Based Detection (#3396)

* 1. use search endpoint

* 2 add rule based detection

* 3. update discovery logic

* add tests, update bundle size limit, update changelog

* @W-19980361 Rule based bonus products- Work Item 2- update display logic (#3408)

* 1. use search endpoint

* 2 add rule based detection

* 3. update discovery logic

* cleanup. remove unused code

* add tests, update bundle size limit, update changelog

* fix header counts

* fix flasing, re-rendering

* pr comments + lint

* @W-19980361 fix 2 bugs- selection count & flashing due to re-renders (#3421)

* fix header counts

* fix flasing, re-rendering

* pr comments + lint

* add param &refine=pmpt=bonus for promotion type

* pr comments

* use commerce sdk

* add const- limit=50  |  replace harded Search Param values

* remove function breakdown change

* update changelog

* refactor. re-use

* fix: prevent promotion message flashing when changing product variant… (#3428)

* fix tests

* Rule-Based Bonus Product Promotions Enhancement

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

* fix: prevent promotion message flashing when changing product variant (#3431)

* fix: prevent promotion flash by keeping previous data during variant changes

- Add keepPreviousData option parameter to useProductViewModal hook
- Pass keepPreviousData: true in BonusProductViewModal to maintain UI stability
- Prevents promotion message from clearing while fetching new variant data

* chore: trigger CI

* remove those stable references

* revert last changes

* bundle size limit update

* @W-20037720: Not allow duplicate items to appear in the cart (#3433)

* Fixed duplicating bonus products in the UI

* Fixed issue with list based not rendering properly

* Update cart-product-list-with-grouped-bonus-products.jsx

Signed-off-by: Daniel Diaz <[email protected]>

* Fixed lint errors

---------

Signed-off-by: Daniel Diaz <[email protected]>

---------

Signed-off-by: Daniel Diaz <[email protected]>
Co-authored-by: sf-xingquan-jin <[email protected]>
Co-authored-by: cboscenco <[email protected]>
Co-authored-by: Daniel Diaz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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