Class PriceCalculator
- Namespace
- Dynamicweb.Ecommerce.Prices
- Assembly
- Dynamicweb.Ecommerce.dll
Common hub for price calculations.
public abstract class PriceCalculator
- Inheritance
-
PriceCalculator
- Inherited Members
Remarks
Register an implementation in the dependency container to take over how the platform calculates VAT, exchanges currencies and rounds money.
Methods
CalculateQualifiedPrice(double, Currency, Country, Currency)
Calculates a qualified price for the specified price value, converted from the default currency to the specified currency.
protected abstract PriceInfo CalculateQualifiedPrice(double price, Currency currency, Country country, Currency defaultCurrency)
Parameters
pricedoubleThe price value in the default currency.
currencyCurrencyThe target currency.
countryCountryThe country used for VAT calculation.
defaultCurrencyCurrencyThe default currency.
Returns
- PriceInfo
The PriceInfo in the provided currency, using the resolved VAT based on the provided country.
ConvertToPIP(Currency?, double)
Converts the specified amount to a value in the smallest monetary unit for the specified Currency.
public abstract long ConvertToPIP(Currency? currency, double amount)
Parameters
currencyCurrencyThe currency that determines the smallest monetary unit. When it has no culture, two decimals are assumed.
amountdoubleThe amount to convert.
Returns
- long
The converted amount in the smallest monetary unit.
ConvertToPIP(int, double)
Converts the specified amount to a value in the smallest monetary unit, given a number of decimals.
protected abstract long ConvertToPIP(int decimalDigits, double amount)
Parameters
decimalDigitsintThe number of decimals the amount is expressed with.
amountdoubleThe amount to convert.
Returns
- long
The converted amount in the smallest monetary unit.
Exchange(double, Currency, Currency)
Converts the specified price from one currency to another.
protected abstract double Exchange(double price, Currency sourceCurrency, Currency destinationCurrency)
Parameters
pricedoubleThe price to convert.
sourceCurrencyCurrencyThe currency the price is in.
destinationCurrencyCurrencyThe currency to convert the price to.
Returns
- double
The price in
destinationCurrency.
Exchange(double, double, double)
Converts the specified price from one currency rate to another.
protected abstract double Exchange(double price, double sourceRate, double destinationRate)
Parameters
pricedoubleThe price to convert.
sourceRatedoubleThe rate of the currency the price is in.
destinationRatedoubleThe rate of the currency to convert the price to.
Returns
- double
The price at
destinationRate.
MinusVat(double, double)
Subtracts VAT from the specified price.
protected abstract double MinusVat(double price, double percent)
Parameters
Returns
- double
The price without VAT.
PlusVat(double, double)
Adds VAT to the specified price.
protected abstract double PlusVat(double price, double percent)
Parameters
Returns
- double
The price including VAT.
Round(Currency?, double)
Rounds the specified price to the number of decimals the currency uses.
public abstract double Round(Currency? currency, double price)
Parameters
currencyCurrencyThe currency that determines the number of decimals. When it has no culture, two decimals are assumed.
pricedoubleThe price to round.
Returns
- double
The rounded price.
Round(int, double)
Rounds the specified price to the specified number of decimals.
public abstract double Round(int decimalDigits, double price)
Parameters
Returns
- double
The rounded price.