Home > widget-integration > RecommendationService > getRecommendationModel
RecommendationService.getRecommendationModel() method
Builds the complete recommendation model for a widget.
This is the main method that orchestrates widget data retrieval, validation, and model construction. Performs validation, fetches products, applies design settings, and creates a RecommendationModel instance. Returns undefined if widget validation fails.
Signature:
getRecommendationModel(widgetId: string): Promise<RecommendationModel | undefined>;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
widgetId |
string |
The widget identifier to build the model for. Must be a valid widget ID that exists in the TAE configuration for the current page. |
Returns:
Promise<RecommendationModel | undefined>
Promise resolving to RecommendationModel instance containing widget data, products, and settings, or undefined if widget validation fails (e.g., widget not configured, wrong page).
Example
Build and render a widget:
const model = await this.getRecommendationModel('homepage-recommendations-1');
if (model) {
await this.renderWidget(model);
} else {
console.log('Widget validation failed');
}