Home > widget-integration > RecommendationWidgetController > calcTotalPrice

RecommendationWidgetController.calcTotalPrice() method

Calculates the total price of checked products in a bundle.

Sums the prices of all selected products in the recommendation bundle. Override this method to apply bundle discounts, tax calculations, or custom pricing logic for specific shops or customer segments.

Signature:

calcTotalPrice(products: RecommendationModelProperties["products"]): number;

Parameters

Parameter

Type

Description

products

RecommendationModelProperties["products"]

Array of recommendation products with selection state and pricing data

Returns:

number

Total price in cents of all checked products, before any additional processing

Example 1

Override to apply bundle discounts:

public calcTotalPrice(products: ExtendedRecommendationProduct[]): number {
  const baseTotal = super.calcTotalPrice(products);
  const checkedCount = products.filter(p => p.checked).length;

  // Apply bundle discount for 3+ items
  if (checkedCount >= 3) {
    return Math.round(baseTotal * 0.85); // 15% bundle discount
  }
  return baseTotal;
}

Example 2

Override to add tax calculation:

public calcTotalPrice(products: ExtendedRecommendationProduct[]): number {
  const subtotal = super.calcTotalPrice(products);
  const taxRate = this.getTaxRateForCustomer();
  return Math.round(subtotal * (1 + taxRate));
}