AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    Administration interface basicsDevelopers and adminsBusiness usersChangelogGlossary
  • Guides
    Welcome to Xperience by KenticoAdministration interface basicsCustomer journeysDigital marketingConfigurationDevelopmentArchitectureUpgrade to Xperience by Kentico
  • Training
    For AdminsFor Business usersFor DevelopersFor Solution architects
  • API Examples
    ConfigurationContent managementDevelopmentDigital marketing
  • Changelog
    Documentation updatesSecurity advisories
  1. Home
  2. Developers and admins
  3. Digital commerce
  4. Price calculation

Price calculation


Was this page helpful?

Send us feedback Go back to top
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)

Advanced license required

Features described on this page require the Xperience by Kentico Advanced license tier.

The price calculation service IPriceCalculationService calculates prices, promotions, taxes, shipping costs, and totals across the entire commerce experience – from product catalog displays through shopping cart summaries to final checkout totals.

Different calculation modes optimize the service for each scenario, running only the steps required for that context. This page explains the calculation pipeline and how to choose the right mode for your use case.

Key points

  • The price calculation service uses a pipeline architecture with sequential calculation steps.
  • Three calculation modes (Catalog, ShoppingCart, Checkout) optimize performance for different scenarios.
  • You must implement a product data retriever to connect the service to your catalog. See Set up price calculation.
  • Tax calculation requires a custom implementation – the default step does not calculate taxes. See Set up price calculation.
  • All calculation steps can be customized or extended to fit your business logic.

Minimum required implementation

To make the price calculation API usable in your project, you need to implement two components:

ComponentRequired forDescription
Product data retrieverAll modesImplements IProductDataRetriever to load product information and pricing data from your catalog. See Implement product data retrieval.
Tax calculation stepShoppingCart, Checkout modesOverrides the default ITaxPriceCalculationStep to calculate taxes. The default implementation does not add taxes. See Set up price calculation.

Once you've implemented and registered these components, the price calculation service automatically handles the rest of the calculation pipeline, including unit price calculations, catalog promotions, subtotals, order promotions, shipping costs, and final totals.

For complete implementation examples, examine the ProductDataRetriever.cs and DancingGoatTaxPriceCalculationStep.cs files in the Dancing Goat sample project.

Calculation modes

The price calculation service supports three calculation modes that determine which steps execute. Set the Mode property on the PriceCalculationRequest to control the calculation scope.

ModeUse caseSteps executed
CatalogProduct listings, category pages, product detail pagesProduct data loading, catalog promotions, line subtotals
ShoppingCartShopping cart display before shipping selectionAll Catalog steps plus order promotions, taxes, line totals, order totals
CheckoutFinal checkout with shippingAll steps including shipping calculation

The default mode is PriceCalculationMode.Catalog. Always set the appropriate mode based on your context to ensure correct calculations and optimal performance.

C#Set calculation mode based on context
using CMS.Commerce;

// ...

var catalogRequest = new PriceCalculationRequest
{
    Items = productItems,
    LanguageName = "en",
    // Defaults to 'Catalog' if not set
    Mode = PriceCalculationMode.Catalog
};

For detailed usage examples of each mode, see Calculate prices.

Price calculation flow

The price calculation service transforms a PriceCalculationRequest into a PriceCalculationResult through a series of sequential steps:

  1. Input preparation – You provide a PriceCalculationRequest containing items to be priced with their product identifiers and quantities. Depending on the calculation mode, you may also include customer details, selected shipping and payment methods, and delivery addresses.

  2. Price calculation steps – The IPriceCalculationService executes a series of calculation steps in sequence. Each step performs a specific pricing task, modifying the PriceCalculationResult as it progresses through the pipeline.

  3. Result compilation – The service returns a PriceCalculationResult containing itemized pricing details, subtotals, shipping costs, taxes, and the grand total.

Calculation steps

The calculation pipeline consists of the following steps, executed sequentially. Each step only runs if included in the selected calculation mode.

StepModesDescription
Load product dataAllLoads product information and pricing data using your IProductDataRetriever implementation
Catalog promotionsAllApplies catalog promotions to individual products (best discount wins)
Line subtotalsAllCalculates line subtotals after catalog discounts
ShippingCheckoutDetermines shipping cost based on the selected shipping method
Order promotionsShoppingCart, CheckoutApplies order promotions that discount the entire order
Free ShippingShoppingCart, CheckoutDetermines whether the order qualifies for free shipping
TaxesShoppingCart, CheckoutCalculates taxes (requires custom implementation)
Line totalsShoppingCart, CheckoutCalculates final line totals including taxes
Order totalShoppingCart, CheckoutSums line subtotals, shipping, and taxes
Grand totalShoppingCart, CheckoutSets the final grand total to be paid

You can customize the default flow by modifying existing steps or adding custom steps to the pipeline.

Calculation walkthrough example

In practice, a Checkout-mode order with two products, an 8% tax rate, and $15.00 flat-rate shipping develops through the steps as follows (tax-exclusive mode, PricesIncludeTax = false):

Input:

  • Item A: 2 × $100.00, with a $10.00/unit catalog promotion
  • Item B: 1 × $50.00, no catalog promotion
  • Order-level promotion: $13.00 off
  • No qualifying free shipping promotion – shipping is charged in full
StepOperationItem AItem BOrder
Load product dataLoad unit prices$100.00$50.00–
Catalog promotionsApply catalog discounts−$10.00/unit(none)–
Line subtotals(Price − Catalog Discount) × Qty($100 − $10) × 2 = $180.00$50 × 1 = $50.00–
ShippingCalculate shipping cost––$15.00
Order promotionsDistribute $13.00 order discount proportionally$13 × ($180 / $230) = $10.17$13 × ($50 / $230) = $2.83–
Free ShippingNo qualifying promotion – shipping cost unchanged–––
Taxes(Subtotal − Order Discount) × Tax Rate($180 − $10.17) × 8% = $13.59($50 − $2.83) × 8% = $3.77–
Line totalsSubtotal − Order Discount + Tax$169.83 + $13.59 = $183.42$47.17 + $3.77 = $50.94–
Order totalSum of Line Totals + Shipping––$183.42 + $50.94 + $15.00 = $249.36
Grand totalFinal order amount––$249.36

General formula

Total = (ΣA − O) × (1 + t) + S × F

Where:

  • A – line subtotal after catalog discount A = (P - D) x Q
  • P – unit price
  • D – catalog discount per unit (fixed amount, or P × discount rate for percentage-based promotions)
  • Q – quantity
  • O – total order promotion discount
  • t – tax rate
  • S – shipping cost
  • F – free shipping factor: 1 if no free shipping promotion is granted (shipping is charged in full), or 0 if the order qualifies for free shipping (shipping cost is removed)

When TaxOptions.PricesIncludeTax is set to true, tax is already included in the unit price – the Tax step extracts it rather than adding it, so the formula becomes (ΣA − O) + S × F. See Configure tax-inclusive pricing.

Basic usage

Inject IPriceCalculationService and call Calculate with a PriceCalculationRequest. The service returns a PriceCalculationResult containing itemized prices, totals, and applied promotions.

C#Calculate prices for cart items
using System.Linq;
using System.Threading.Tasks;

using CMS.Commerce;

using Microsoft.AspNetCore.Mvc;

public class ShoppingCartController : Controller
{
    private readonly IPriceCalculationService<PriceCalculationRequest, PriceCalculationResult> priceCalculationService;

    public ShoppingCartController(IPriceCalculationService<PriceCalculationRequest, PriceCalculationResult> priceCalculationService)
    {
        this.priceCalculationService = priceCalculationService;
    }

    public async Task<IActionResult> Index(ShoppingCartDataModel shoppingCartData)
    {
        // Build the request with items to price
        var request = new PriceCalculationRequest
        {
            Items = shoppingCartData.Items.Select(item => new PriceCalculationRequestItem
            {
                ProductIdentifier = item.ProductIdentifier,
                Quantity = item.Quantity
            }).ToList(),
            LanguageName = "en",
            Mode = PriceCalculationMode.ShoppingCart
        };

        // Calculates cart prices
        PriceCalculationResult result = await priceCalculationService.Calculate(request);

        // Process the calculation result...
    }
}

For complete examples of each calculation mode, see Calculate prices.

Multi-currency support

The price calculation service operates with a single currency by default. If your store requires multi-currency support, you need to implement it as part of your custom solution, for example:

  • Store alternate prices in custom fields on your product content type and select the appropriate price in your IProductDataRetriever implementation based on the customer's currency preference.
  • Create a custom calculation step that performs currency conversion using exchange rates from an external service or configuration data.
  • Integrate with a third-party pricing service that handles multi-currency pricing.

Next steps

  • Set up price calculation – Implement product data retrieval and use the calculation service
  • Customize price calculation – Extend data objects, modify calculation steps, or add custom steps
  • Checkout process – Integrate price calculation into your checkout process

On this page

  • Minimum required implementation
  • Calculation modes
  • Price calculation flow
    • Calculation steps
    • Calculation walkthrough example
  • Basic usage
  • Next steps