Class PriceViewModelExtensions
- Namespace
- Dynamicweb.Ecommerce.ProductCatalog
- Assembly
- Dynamicweb.Ecommerce.dll
Extensions for price view model
public static class PriceViewModelExtensions
- Inheritance
-
PriceViewModelExtensions
- Inherited Members
Methods
GetVatLabel(PriceViewModel)
Converts a PriceVatMode value to its corresponding English text.
public static string GetVatLabel(this PriceViewModel price)
Parameters
pricePriceViewModelThe price view model.
Returns
- string
Textual representation, empty string for None.
GetVatMode(PriceViewModel)
Returns a compact VAT label state for the current user context. ShowPricesWithVat => InclusiveVat ReverseChargeForVat => ExclusiveVatReverseCharge Else => ExclusiveVat Null price => None
public static PriceVatMode GetVatMode(this PriceViewModel price)
Parameters
pricePriceViewModelThe price view model.
Returns
- PriceVatMode
The PriceVatMode enum value representing the VAT display state.
ToPriceViewModel(PriceViewModel)
Converts the frontend price view model to the ecommerce price view model for simplifying rendering.
public static PriceViewModel? ToPriceViewModel(this PriceViewModel price)
Parameters
pricePriceViewModelThe frontend price view model.
Returns
- PriceViewModel
The converted ecommerce price view model.
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
pricePriceViewModelThe 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
pricePriceViewModelThe PriceViewModel instance.
showWithVatboolif set to
truethe 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)
Attempts to get the VAT label for the specified price.
public static bool TryGetVatLabel(this PriceViewModel price, out string label)
Parameters
pricePriceViewModelThe price view model (may be null).
labelstringOutputs the VAT label if available; otherwise an empty string.
Returns
- bool
True if GetVatLabel(PriceViewModel) returns a non-empty label; otherwise false.