Home > widget-integration > CartDrawerRecommendationService > parsePrice

CartDrawerRecommendationService.parsePrice() method

Parse a price value from API response.

The API may return prices as numbers or strings (e.g., "20.0"). This method normalizes them to numbers for formatting.

Signature:

protected parsePrice(price: unknown): number | null;

Parameters

Parameter

Type

Description

price

unknown

Price value from API (number or string)

Returns:

number | null

Parsed number, or null if invalid/empty

Example

Override to handle a custom price format:

protected parsePrice(price: unknown) {
  // Handle comma-separated decimals (e.g., "19,99")
  if (typeof price === 'string' && price.includes(',')) {
    return parseFloat(price.replace(',', '.'));
  }
  return super.parsePrice(price);
}