CoolCMS API

ApproximatePrice
in package

FinalYes

Approximate amount conversion between currencies using the manual rate `cms_system_currencies.exchange_rate`.

IMPORTANT: the rate means foreign currency per 1 CZK (CZK = 1, EUR = 0.041), the same as in Store (DocumentService, "base = unit_price / rate") and the SMS gateway (MobilniplatbyGateway). Converting from A to B is amount / rateA * rateB; mixing up the direction inverts every converted price.

The result is only an indicative addition to the original (100 000 CZK (≈ €4,100)); no price is stored or filtered by it. Showing nothing is better than showing nonsense, so null is returned for:

  • a missing or non-positive amount,
  • the same currency (nothing to convert),
  • a non-monetary currency on either side (credits are not money; an internal monetary currency is still converted),
  • a missing or zero rate.

Latte rendering: filter approxPrice (ApproxPriceLatteExtension).

Table of Contents

Constants

WHOLE_UNITS_FROM  : mixed = 10.0
From this amount the conversion is rounded to whole units ("≈ €4,100", not "€4,100.00").

Methods

convert()  : float|null
format()  : string
Formats an approximate amount by the localization (fallback currency), the same path as the `priceFormat` filter ({@see PriceHelper::convertByLocalization()}), but whole amounts without decimals: "€4,100", not "€4,100.00" (`/en/` has the suffix off, so it would show zeros).
isConvertible()  : bool
Monetary currency with a positive rate; units (credits) are not converted. A hidden (internal) monetary currency is.
round()  : float
Rounds an approximate amount: to whole units from {@see WHOLE_UNITS_FROM}, to hundredths below it.
formatSource()  : object
Format source for {@see PriceFormat::resolve()}: the resolved format with an overridden precision.
rate()  : float

Constants

WHOLE_UNITS_FROM

From this amount the conversion is rounded to whole units ("≈ €4,100", not "€4,100.00").

public mixed WHOLE_UNITS_FROM = 10.0

Methods

convert()

public static convert(float|int|string|null $amount, object|null $from, object|null $to) : float|null
Parameters
$amount : float|int|string|null
$from : object|null
$to : object|null
Return values
float|null

format()

Formats an approximate amount by the localization (fallback currency), the same path as the `priceFormat` filter ({@see PriceHelper::convertByLocalization()}), but whole amounts without decimals: "€4,100", not "€4,100.00" (`/en/` has the suffix off, so it would show zeros).

public static format(float $amount, object $currency[, object|null $localization = null ][, string|null $unit = null ]) : string
Parameters
$amount : float
$currency : object
$localization : object|null = null
$unit : string|null = null
Return values
string

isConvertible()

Monetary currency with a positive rate; units (credits) are not converted. A hidden (internal) monetary currency is.

public static isConvertible(object|null $currency) : bool
Parameters
$currency : object|null
Return values
bool

round()

Rounds an approximate amount: to whole units from {@see WHOLE_UNITS_FROM}, to hundredths below it.

public static round(float $amount) : float
Parameters
$amount : float
Return values
float

formatSource()

Format source for {@see PriceFormat::resolve()}: the resolved format with an overridden precision.

private static formatSource(PriceFormat $format, int $precision) : object

resolve() reads the localization through getters, so any object returning them is enough.

Parameters
$format : PriceFormat
$precision : int
Return values
object

rate()

private static rate(object $currency) : float
Parameters
$currency : object
Return values
float
On this page

Search results