-
Notifications
You must be signed in to change notification settings - Fork 201
@W-18957985- Product Search Integration & Rule-Based Detection #3396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sf-shikhar-prasoon
merged 7 commits into
feature/bonus-products-rule-based-v3
from
t/cc-sharks/W-18957985/rule-based-w1/main
Oct 21, 2025
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0d82e65
1. use search endpoint
sf-shikhar-prasoon 2622638
2 add rule based detection
sf-shikhar-prasoon b4f4b7c
3. update discovery logic
sf-shikhar-prasoon b36ea26
cleanup. remove unused code
sf-shikhar-prasoon 5ecf92a
add tests, update bundle size limit, update changelog
sf-shikhar-prasoon bcbed7a
refactor
sf-shikhar-prasoon 2038ca2
fix tests
sf-shikhar-prasoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
50 changes: 50 additions & 0 deletions
50
packages/template-retail-react-app/app/hooks/use-rule-based-bonus-products.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Copyright (c) 2025, Salesforce, Inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import {useProductSearch} from '@salesforce/commerce-sdk-react' | ||
|
|
||
| /** | ||
| * Hook to fetch rule-based bonus products using ShopperSearch productSearch endpoint. | ||
| * | ||
| * For rule-based bonus promotions, bonusProducts array is empty in the basket response. | ||
| * This hook uses the productSearch endpoint with promotionId to fetch eligible bonus products. | ||
| * | ||
| * @param {string} promotionId - The promotion ID to fetch bonus products for | ||
| * @param {Object} options - Additional options | ||
| * @param {boolean} [options.enabled=true] - Whether to fetch products | ||
| * @param {number} [options.limit=25] - Maximum number of products to return | ||
| * @param {number} [options.offset=0] - Offset for pagination | ||
| * @returns {Object} React Query result with products data | ||
| * | ||
| * @example | ||
| * const {products, isLoading, error} = useRuleBasedBonusProducts( | ||
| * 'my-promotion-id', | ||
| * {enabled: isModalOpen} | ||
| * ) | ||
| */ | ||
| export const useRuleBasedBonusProducts = (promotionId, {enabled = true, limit, offset} = {}) => { | ||
| const {data, isLoading, error, ...rest} = useProductSearch( | ||
| { | ||
| parameters: { | ||
| promotionId, | ||
| limit: limit || 25, | ||
| offset: offset || 0 | ||
| } | ||
| }, | ||
| { | ||
| enabled: enabled && Boolean(promotionId) | ||
| } | ||
| ) | ||
|
|
||
| return { | ||
| products: data?.hits || [], | ||
| total: data?.total || 0, | ||
| isLoading, | ||
| error, | ||
| ...rest | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.