Home > widget-integration > RecommendationService > getCurrentProductId
RecommendationService.getCurrentProductId() method
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.
Signature:
protected getCurrentProductId(): Promise<(string | number)[]>;
Returns:
Promise<(string | number)[]>
Promise resolving to array containing the current product ID (string or number). Returns empty array if no product is currently loaded in the platform context.
Example
Override to use variant ID instead of product ID:
protected async getCurrentProductId(): Promise<(string | number)[]> {
const { product } = this.platformLoader.platform;
const selectedVariant = this.getSelectedVariant();
return selectedVariant?.id ? [selectedVariant.id] : [];
}