Commit 31d17a2
Add support for Rule Based Promotions for Choice of Bonus Products (#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]>1 parent 9ecf901 commit 31d17a2
File tree
31 files changed
+2457
-198
lines changed- packages/template-retail-react-app
- app
- components/bonus-product-view-modal
- hooks
- use-bonus-product-selection-modal
- components
- pages/cart
- partials
- utils/bonus-product
31 files changed
+2457
-198
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
1 | 4 | | |
2 | 5 | | |
3 | 6 | | |
| |||
Lines changed: 45 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | 27 | | |
29 | 28 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 29 | + | |
34 | 30 | | |
35 | 31 | | |
36 | 32 | | |
| |||
64 | 60 | | |
65 | 61 | | |
66 | 62 | | |
67 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
68 | 87 | | |
69 | 88 | | |
70 | 89 | | |
| |||
99 | 118 | | |
100 | 119 | | |
101 | 120 | | |
102 | | - | |
| 121 | + | |
103 | 122 | | |
104 | 123 | | |
105 | 124 | | |
| |||
110 | 129 | | |
111 | 130 | | |
112 | 131 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 132 | + | |
125 | 133 | | |
126 | 134 | | |
127 | 135 | | |
128 | 136 | | |
129 | 137 | | |
130 | 138 | | |
131 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
132 | 144 | | |
133 | 145 | | |
134 | 146 | | |
135 | 147 | | |
136 | 148 | | |
137 | | - | |
| 149 | + | |
138 | 150 | | |
139 | 151 | | |
140 | 152 | | |
| |||
190 | 202 | | |
191 | 203 | | |
192 | 204 | | |
193 | | - | |
| 205 | + | |
| 206 | + | |
194 | 207 | | |
195 | 208 | | |
196 | 209 | | |
| |||
239 | 252 | | |
240 | 253 | | |
241 | 254 | | |
242 | | - | |
| 255 | + | |
243 | 256 | | |
244 | 257 | | |
245 | 258 | | |
| |||
365 | 378 | | |
366 | 379 | | |
367 | 380 | | |
368 | | - | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
369 | 387 | | |
370 | | - | |
371 | | - | |
| 388 | + | |
| 389 | + | |
372 | 390 | | |
373 | 391 | | |
374 | 392 | | |
| |||
427 | 445 | | |
428 | 446 | | |
429 | 447 | | |
430 | | - | |
| 448 | + | |
| 449 | + | |
431 | 450 | | |
432 | 451 | | |
433 | 452 | | |
| |||
Lines changed: 22 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| |||
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
45 | 61 | | |
46 | 62 | | |
47 | 63 | | |
| |||
117 | 133 | | |
118 | 134 | | |
119 | 135 | | |
120 | | - | |
| 136 | + | |
| 137 | + | |
121 | 138 | | |
122 | 139 | | |
123 | 140 | | |
| |||
171 | 188 | | |
172 | 189 | | |
173 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
174 | 194 | | |
175 | 195 | | |
176 | 196 | | |
| |||
Lines changed: 50 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
25 | | - | |
| 29 | + | |
| 30 | + | |
26 | 31 | | |
27 | 32 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
34 | 70 | | |
35 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
36 | 78 | | |
37 | 79 | | |
38 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
Lines changed: 29 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | | - | |
| 89 | + | |
| 90 | + | |
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
| |||
323 | 325 | | |
324 | 326 | | |
325 | 327 | | |
326 | | - | |
| 328 | + | |
| 329 | + | |
327 | 330 | | |
328 | 331 | | |
329 | 332 | | |
| |||
335 | 338 | | |
336 | 339 | | |
337 | 340 | | |
338 | | - | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
339 | 344 | | |
340 | 345 | | |
341 | 346 | | |
| |||
348 | 353 | | |
349 | 354 | | |
350 | 355 | | |
351 | | - | |
352 | | - | |
353 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
354 | 375 | | |
355 | 376 | | |
356 | 377 | | |
| |||
363 | 384 | | |
364 | 385 | | |
365 | 386 | | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
| 387 | + | |
374 | 388 | | |
375 | 389 | | |
376 | 390 | | |
| |||
Lines changed: 3 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | 30 | | |
35 | 31 | | |
36 | 32 | | |
| |||
106 | 102 | | |
107 | 103 | | |
108 | 104 | | |
109 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
110 | 108 | | |
111 | 109 | | |
112 | 110 | | |
| |||
0 commit comments