Home > widget-integration > CartDrawerRecommendationService > formatPrice

CartDrawerRecommendationService.formatPrice() method

Format a price value for display.

Uses AppService.formatCurrency for consistent store-wide formatting. Override this method to customize price formatting.

Signature:

protected formatPrice(price: number | undefined | null, showCurrencyCodes: boolean): string;

Parameters

Parameter

Type

Description

price

number | undefined | null

Price value from Recommendation API (e.g., 19.99 or 100)

showCurrencyCodes

boolean

Whether to show currency codes (e.g., "USD")

Returns:

string

Formatted price string (e.g., "$19.99" or "$19.99 USD"), or empty string if price is null/undefined

Remarks

Recommendation API returns prices already in the store's currency unit (e.g., 19.99 for $19.99, 100 for 100 VND), NOT in cents like Shopify Cart API.

Example

Override to apply shop-specific rounding or custom currency display:

window.boostWidgetIntegration.extend('CartDrawerRecommendationService', (Base) => {
  return class extends Base {
    formatPrice(price, showCurrencyCodes) {
      if (price != null) price = Math.round(price); // Round to whole number
      return super.formatPrice(price, showCurrencyCodes);
    }
  };
});