Home > widget-integration > RecommendationService > getCartProductIds
RecommendationService.getCartProductIds() method
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).
Signature:
protected getCartProductIds(): Promise<number[]>;
Returns:
Promise<number[]>
Promise resolving to array of product IDs (numbers) from the customer's cart. Returns empty array if the cart is empty or unavailable.
Example
Override to filter cart products by type:
protected async getCartProductIds(): Promise<number[]> {
  const products = await this.cartAPI.getProductsInCart();
  // Exclude gift cards and downloadable products
  return products
    .filter(p => !p.tags?.includes('gift-card'))
    .filter(p => !p.tags?.includes('downloadable'))
    .map(p => p.product_id);
}