Home > widget-integration > RecommendationService

RecommendationService class

Service for managing recommendation widgets and their data.

Signature:

export declare class RecommendationService 

Constructors

Constructor

Modifiers

Description

(constructor)(moduleRef, appService, platformLoader, templateAPI, recentlyViewedProductService, cartAPI, recommendationAPI)

Constructs a new instance of the RecommendationService class

Properties

Property

Modifiers

Type

Description

appService

protected

AppService

cartAPI

protected

CartAPI

defaultWidgetSettings

readonly

BoostTAEConfig["recommendationWidgets"]["defaultSettings"] | Record<string, never>

moduleRef

protected

ModuleRefImpl

platformLoader

protected

PlatformLoader

recentlyViewedProductService

protected

RecentlyViewedProductService

recommendationAPI

protected

RecommendationAPI

templateAPI

protected

TemplateAPI

widgets

readonly

BoostTAEConfig["recommendationWidgets"]

Methods

Method

Modifiers

Description

getCartProductIds()

protected

Retrieves product IDs from the customer's cart.

This method can be overridden to customize which cart products should be used for recommendations (e.g., excluding gift cards, downloadable items, sale items, or products from specific collections).

getCurrentProductId()

protected

Retrieves the current product ID from the platform context.

This method can be overridden to customize product page behavior, such as using variant IDs instead of product IDs, including related products, or adding products from the same collection.

getRecentlyViewedProductIds()

protected

Retrieves product IDs for recently viewed products.

This method can be overridden to customize which recently viewed products should be used for recommendations (e.g., filtering by category, availability, or recency threshold).

getRecommendationModel(widgetId)

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.

getRecommendationWidgetConfig(widgetId)

Retrieves the configuration for a specific recommendation widget.

Looks up the widget in the TAE configuration based on the widget ID and its page type.

getRecommendationWidgetProducts(widgetId)

Fetches recommendation products for a widget from the API.

Builds request parameters from widget configuration and makes API call to retrieve recommended products. Handles different recommendation types and includes necessary context (customer ID, collection ID, locale, product IDs).

getWidgetProductIds(widgetId)

Retrieves product IDs for a specific widget based on recommendation type and page context.

This method orchestrates calls to specific product ID retrieval methods based on the recommendation type and current page. Can be overridden for complex custom logic that doesn't fit the default flow.

getWidgetTemplate()

Retrieves the widget template from TAE config or API.

First attempts to use a template from the TAE configuration if available. Falls back to fetching from the template API using the template metadata ID.

identifyWidgetPage(payload)

Identifies which page type a widget belongs to based on its ID.

Widget IDs follow a naming convention where the prefix indicates the page type: - 'homepage' prefix → home-page - 'cartpage' prefix → cart-page - 'collectionpage' prefix → collection-page - 'productpage' prefix → product-page

rebuildProductDataFromShopifyData(product)

Rebuilds product data from Shopify format to Boost format.

This method transforms Shopify product data structure to match the format expected by the recommendation widget. Can be overridden to customize the overall product transformation logic or add custom product fields.

transformVariantData(variant)

protected

Transforms a single product variant from Shopify format.

This method can be overridden to customize variant data transformation, such as applying custom pricing, adding custom fields, modifying image URLs, or applying shop-specific business logic.

validateWidget(payload)

Validates whether a widget should be rendered based on configuration and page context.

Performs comprehensive validation including: - Widget ID presence and format - Page type identification - Current page context matching - Widget configuration existence - Widget settings completeness - Template metadata availability