Implementing Dynamically Priced Products

Learn how to implement dynamically priced products in Umbraco Commerce.

Sometimes products do not have a fixed price. Depending on the customer's requirements, the price of the product can change. Examples could be window blinds that a priced based on the size of the window, or wallpaper that is priced by the meter.

This guide shows you how to implement dynamically priced products in Umbraco Commerce.

This guide is not a direct follow-on from the getting started tutorial. It is assumed that your store is set up in a similar structure.

Capturing User Input

Add a new field on the product's frontend page, to capture the desired length we want to purchase.

Length Input

The selected length will reflect on the cart value.

Calculated Cart Values

To provide the correct calculations for an order, the captured data will need to go through two different processes behind the scenes:

  • Store the user input against the order line property.

  • Implement a custom order line calculator to calculate the prices based on the user input.

Storing the User Input

  1. Add a new property to the AddToCartDto class to capture the length.

  1. Update the AddToCart method of the CartSurfaceController to store the length against the order line as a property.

Calculating the Order Line Price

We will calculate the price/tax rate of a given order line by multiplying the specified length by the unit price. This is done using a custom order line calculator.

  1. Create a new class that implements the IOrderLineCalculator interface.

  1. Register the custom calculator in the Startup.cs file or in an IComposer.

Backoffice UI

A useful extra step is to expose the captured data in the order's details in the Backoffice.

This is implemented as a custom UI Extension.

Create a new umbraco-package.json file in a folder in the App_Plugins directory in the root of your project and add the following code:

The length property is now displayed in the order details in the Backoffice.

Order Details

Last updated

Was this helpful?