Table of Contents

Class PriceViewModelExtensions

Namespace
Dynamicweb.Ecommerce.ProductCatalog
Assembly
Dynamicweb.Ecommerce.dll

Extension methods for PriceViewModel that provide analytics-friendly formatting, VAT label helpers, and conversion from the frontend price model.

public static class PriceViewModelExtensions
Inheritance
PriceViewModelExtensions
Inherited Members

Remarks

The most commonly used methods in Razor templates:

Methods

GetVatLabel(PriceViewModel)

Returns the localizable English VAT label for the price (e.g. "incl. VAT").

public static string GetVatLabel(this PriceViewModel price)

Parameters

price PriceViewModel

The price view model.

Returns

string

One of "incl. VAT", "excl. VAT", "excl. VAT (reverse charge)", or an empty string when GetVatMode(PriceViewModel) returns None. The returned strings are stable and intended to be wrapped in a Translate call in templates.

See Also

GetVatMode(PriceViewModel)

Returns the VAT display mode for the price, useful for driving switch-based rendering logic.

public static PriceVatMode GetVatMode(this PriceViewModel price)

Parameters

price PriceViewModel

The price view model.

Returns

PriceVatMode
ValueCondition
Noneprice is null or VAT amount is 0.
InclusiveVatShowPricesWithVat is true.
ExclusiveVatReverseChargeReverseChargeForVat is true.
ExclusiveVatPrices are shown ex-VAT without reverse charge.
See Also

ToPriceViewModel(PriceViewModel)

Converts a PriceViewModel (used in non-ecommerce frontend contexts) into an ecommerce PriceViewModel so that the same Razor price-rendering helpers apply.

public static PriceViewModel? ToPriceViewModel(this PriceViewModel price)

Parameters

price PriceViewModel

The frontend price view model to convert.

Returns

PriceViewModel

A populated ecommerce PriceViewModel; null when price is null.

ToStringInvariant(PriceViewModel)

Converts the price to a string representation using the invariant culture ensuring . (dot) is used as decimal point symbol and always with 2 decimals and thousand separator is not used.

public static string ToStringInvariant(this PriceViewModel price)

Parameters

price PriceViewModel

The PriceViewModel instance.

Returns

string

A string representation of the price using e.g. '1234.45' or '2340.00'. If price is null, empty string is returned

Remarks

This method can be used to get the price formatted for e.g. analytics, google tag-manager and other services that require a specific format of prices. When called, the 'display price' is used - meaning that if the prices are currently showed with VAT, the price with VAT is used, otherwise the price without VAT is used.

ToStringInvariant(PriceViewModel, bool)

Converts the price to a string representation using the invariant culture ensuring . (dot) is used as decimal point symbol and always with 2 decimals and thousand separator is not used.

public static string ToStringInvariant(this PriceViewModel price, bool showWithVat)

Parameters

price PriceViewModel

The PriceViewModel instance.

showWithVat bool

if set to true the price with VAT is used, otherwise the price without VAT is used.

Returns

string

A string representation of the price using e.g. '1234.45' or '2340.00'. If price is null, empty string is returned

Remarks

This method can be used to get the price formatted for e.g. analytics, google tag-manager and other services that require a specific format of prices.

TryGetVatLabel(PriceViewModel, out string)

Tries to get the VAT label for the price, returning false when no label applies. Prefer this over GetVatLabel(PriceViewModel) in templates to avoid rendering an empty span.

public static bool TryGetVatLabel(this PriceViewModel price, out string label)

Parameters

price PriceViewModel

The price view model; may be null.

label string

When this method returns true, contains the VAT label string (e.g. "incl. VAT"); otherwise an empty string.

Returns

bool

true when a non-empty VAT label exists for this price; false when price is null or VAT is zero.

See Also

To top