Home > widget-integration > RecommendationWidgetController > formatPrice
RecommendationWidgetController.formatPrice() method
Formats a price value according to shop settings and theme configuration.
Applies shop-specific currency formatting including decimal handling, superscript cents, and currency symbols. Override this method to implement custom price formatting logic, add discounts, or modify display for specific customer segments.
Signature:
formatPrice(price: number): string;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
price |
number |
The price value in cents to format |
Returns:
string
Formatted price string with currency symbol and shop-specific styling applied
Example 1
Override to add VIP customer discounts:
public formatPrice(price: number): string {
let adjustedPrice = price;
if (this.customer?.tags?.includes('vip')) {
adjustedPrice = price * 0.9; // 10% VIP discount
}
return super.formatPrice(adjustedPrice);
}
Example 2
Override to add custom currency formatting:
public formatPrice(price: number): string {
const formatted = super.formatPrice(price);
// Add custom formatting for specific regions
return this.customer?.region === 'EU' ? `€${formatted}` : formatted;
}