|
| 1 | +# Product Selection Lightning Web Component |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The `productSelection` Lightning Web Component (LWC) is designed for Digital Insurance product selection workflows. It extends `OmniscriptBaseMixin` to integrate seamlessly with OmniScripts, and makes it easy for users to view, compare, and select rated insurance products. |
| 6 | + |
| 7 | +The component supports both **single-select** and **multi-select** modes, displays product cards with pricing information, and includes a product comparison modal. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Dependencies |
| 12 | + |
| 13 | +- **Apex Controller**: `InsuranceRatingApexService.postRatingFromLwc` |
| 14 | +- **Mixin**: `c/omniscriptBaseMixin` (follow the steps under [Prerequisites](../../../README.md#prerequisites)) |
| 15 | +- **Helper Modules**: |
| 16 | + - `dataManager.js` – Tree building and grid transformation utilities |
| 17 | + - `labelsAndConstants.js` – Validation messages, labels, and constants |
| 18 | + |
| 19 | +## Components Included |
| 20 | + |
| 21 | +| Component | Description | |
| 22 | +| :---- | :---- | |
| 23 | +| `productSelection` | Main component for displaying and selecting rated products | |
| 24 | +| `productSelectionCompareModal` | Modal dialog for comparing 2-3 selected products | |
| 25 | +| `productSelectionCustomTreeGrid` | Extended `lightning-treeGrid` with custom cell rendering | |
| 26 | +| `productSelectionCustomTemplate` | Custom cell template for various data types such as currency, date, and lookup. | |
| 27 | + |
| 28 | +### Supporting Files |
| 29 | + |
| 30 | +| File | Type | Description | |
| 31 | +| :---- | :---- | :---- | |
| 32 | +| `InsuranceRatingApexService.cls` | Apex Class | Service class that wraps the `createInsuranceRating` invocable action | |
| 33 | +| `ProductSelectionLabels.labels` | Custom Labels | UI text labels for translation support | |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## Public Properties (`@api`) |
| 38 | + |
| 39 | +| Property | Type | Default | Description | |
| 40 | +| :---- | :---- | :---- | :---- | |
| 41 | +| `additionalFields` | `Object` | `{}` | Additional fields to include in the rating request payload. | |
| 42 | +| `clearStateOnChange` | `String` | — | JSON stringified array of element names whose state should be cleared when selection changes. | |
| 43 | +| `clearStateOnPrev` | `Boolean/String` | — | When `true` or `'true'`, enables custom navigation buttons and clears state when navigating to the previous step. | |
| 44 | +| `effectiveDate` | `String` | — | The effective date for rating calculations. | |
| 45 | +| `enableMultiSelect` | `Boolean` | `false` | Enables multi-select mode allowing users to select multiple products. | |
| 46 | +| `multiSelectMax` | `Number` | `10` | Maximum number of products that can be selected in multi-select mode. | |
| 47 | +| `ratedProdDescriptions` | `Array` | `[]` | Array of description objects `{rootProductCode, rootInstanceKey, ratingDescription}` for custom product descriptions. | |
| 48 | +| `ratingInputs` | `Array` | `[]` | Array of rating input objects containing product configuration data. Supports reusable and non-reusable inputs with `instanceKeys`. | |
| 49 | +| `ratingOptions` | `Object` | `{}` | Rating options passed to the API. Defaults `executePricing` and `executeConfigurationRules` to `true`. | |
| 50 | +| `rootProductCodes` | `Array` | `[]` | Array of root product codes to rate. Define when the rating inputs are marked as reusable. | |
| 51 | +| `transactionType` | `String` | — | The transaction type for the rating request | |
| 52 | + |
| 53 | +Rating inputs and options are based on the [Insurance Product Rating API](https://developer.salesforce.com/docs/atlas.en-us.insurance_developer_guide.meta/insurance_developer_guide/connect_resources_product_rating.htm%20%20). |
| 54 | + |
| 55 | +## HTML Markup |
| 56 | + |
| 57 | +### Product Card Layout |
| 58 | + |
| 59 | +Each card displays: |
| 60 | + |
| 61 | +- **Product title** – With 2-line text clamp and ellipsis overflow |
| 62 | +- **Premium amount** – Formatted using `lightning-formatted-number` with currency |
| 63 | +- **Description** – With 3-line text clamp and ellipsis overflow |
| 64 | + |
| 65 | +### Conditional Custom Navigation |
| 66 | + |
| 67 | +When `clearStateOnPrev` is true, the component renders custom Previous/Next buttons for state management control: |
| 68 | + |
| 69 | +```html |
| 70 | +<template lwc:if={showCustomNextPrevButtons}> |
| 71 | + <lightning-button label="Previous" onclick={handleCustomPrevious} ... /> |
| 72 | + <lightning-button label="Next" onclick={handleCustomNext} ... /> |
| 73 | +</template> |
| 74 | +``` |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## Component Usage |
| 79 | + |
| 80 | +Embed the productSelection LWC in an Omniscript by using the Custom Lightning Web Component element in a step. |
| 81 | + |
| 82 | +### Adding to an OmniScript Step |
| 83 | + |
| 84 | +1. Open your OmniScript in OmniStudio Designer |
| 85 | +2. Add a **Custom Lightning Web Component** element to your step |
| 86 | +3. Set the **LWC Component Name** to `c-product-selection` |
| 87 | +4. Configure the component properties (see [Public Properties](#public-properties-api)) |
| 88 | + |
| 89 | +If you set `clearStateOnPrev` to `true`, hide the standard Previous and Next buttons in the step by reducing their width to 0\. The productSelection LWC shows Previous and Next buttons for navigation. |
| 90 | + |
| 91 | +### Data Output Structure |
| 92 | + |
| 93 | +The component outputs data to OmniScript via `omniUpdateDataJson()`: |
| 94 | + |
| 95 | +```javascript |
| 96 | +{ |
| 97 | + errors: [{ message: "Error message" }], |
| 98 | + selectedProducts: [ |
| 99 | + { |
| 100 | + contextId: "contextId-123", |
| 101 | + ratingInputs: [ |
| 102 | + { |
| 103 | + productCode: "PROD_001", |
| 104 | + instanceKeys: ["key1", "key2"], |
| 105 | + reusable: false |
| 106 | + } |
| 107 | + ] |
| 108 | + } |
| 109 | + ] |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## Customization |
| 116 | + |
| 117 | +### Styling |
| 118 | + |
| 119 | +The productSelection LWC uses the Salesforce Lightning Design System (SLDS) for styling. |
| 120 | + |
| 121 | +### Adding Custom Product Descriptions |
| 122 | + |
| 123 | +Pass custom descriptions via the `ratedProdDescriptions` property: |
| 124 | + |
| 125 | +```json |
| 126 | +{ |
| 127 | + "ratedProdDescriptions": [ |
| 128 | + { |
| 129 | + "rootProductCode": "AUTO_POLICY", |
| 130 | + "rootInstanceKey": "policy-1", |
| 131 | + "ratingDescription": "Comprehensive auto coverage with roadside assistance" |
| 132 | + } |
| 133 | + ] |
| 134 | +} |
| 135 | +``` |
| 136 | + |
| 137 | +If both rootProductCode and rootInstanceKey are provided, rootInstanceKey takes precedence. |
| 138 | + |
| 139 | +### Constants Configuration |
| 140 | + |
| 141 | +Edit `labelsAndConstants.js` to modify: |
| 142 | + |
| 143 | +- `MIN_PRODUCTS_FOR_COMPARISON`: The minimum number of products that the user must select for comparison. The default value is 2\. |
| 144 | +- `MAX_PRODUCTS_FOR_COMPARISON`: The maximum number of products that the user can select for comparison. The default value is 3\. |
| 145 | +- `MAX_ROOT_PRODUCTS`: The maximum number of root products that the user can select. The default value is 10\. |
| 146 | +- `MAX_CHAR_LIMIT`: Character limit for descriptions (default: 150\) The maximum number of characters that the user can enter in the description. The default value is 150\. |
| 147 | + |
| 148 | +### Custom Labels |
| 149 | + |
| 150 | +These custom labels are included and can be customized or translated: |
| 151 | + |
| 152 | +| Label API Name | Default Value | Purpose | |
| 153 | +| :---- | :---- | :---- | |
| 154 | +| `ProdSelMinComparisonValidation` | Select at least {0} products to compare | Validation message | |
| 155 | +| `ProdSelMaxComparisonValidation` | Select up to {0} products to compare. | Validation message | |
| 156 | +| `ProdSelMaxMultiSelectValidation` | Choose no more than {0} products. | Validation message | |
| 157 | +| `ProdSelMaxRootProductValidation` | No more than {0} root products are allowed for input. | Validation message | |
| 158 | +| `ProdSelSelectionRequiredMsg` | Choose a product. | Validation message | |
| 159 | +| `ProdSelNoProductsMsg` | No products are available. | Empty state message | |
| 160 | +| `ProdSelCompareBtn` | Compare | Button label | |
| 161 | +| `ProdSelDetails` | Details | Column header | |
| 162 | +| `ProdSelNext` | Next | Button label | |
| 163 | +| `ProdSelPremium` | Premium | Label text | |
| 164 | +| `ProdSelPrevious` | Previous | Button label | |
| 165 | +| `ProdSelProduct` | Product | Column header | |
| 166 | +| `ProdSelLoading` | Loading | Spinner alt text | |
| 167 | +| `ProdSelCheckbox` | checkbox | Accessibility label | |
| 168 | +| `ProdSelCompareProducts` | Compare Products | Modal header | |
| 169 | +| `ProdSelCancel` | Cancel | Button label | |
| 170 | + |
| 171 | +## Troubleshooting |
| 172 | + |
| 173 | +### Common Issues |
| 174 | + |
| 175 | +| Issue | Possible Cause | Solution | |
| 176 | +| :---- | :---- | :---- | |
| 177 | +| "No products are available" | Rating API returned no products or ran into error | Verify `rootProductCodes` and `ratingInputs` are correct. | |
| 178 | +| OmniscriptBaseMixin not found on component deployment | Missing Omniscript customization package | Ensure `omniscriptBaseMixin` and utility modules are deployed by following the [Prerequisites](../../../README.md#prerequisites). | |
| 179 | +| Missing context or product details on rating call response | Wrong API version | Ensure that all components and supporting files use Salesforce API version **66.0** or later. | |
| 180 | +| State not persisting | clearStateOnPrev is not set to true | Hide step buttons by setting width to 0 and set `clearStateOnPrev` to true. | |
| 181 | + |
| 182 | +### Debugging |
| 183 | + |
| 184 | +1. **Debug Logs:** Enable debug logs for the `InsuranceRatingApexService` class. |
| 185 | +2. **Browser console:** The component logs errors to the console. |
| 186 | +3. **OmniScript data panel:** Check the data JSON for output values. |
| 187 | + |
| 188 | +## API Version |
| 189 | + |
| 190 | +All components and supporting files must use Salesforce API version **66.0** or later. |
0 commit comments