Calculation
Class Calculation Provides methods for product price calculation (discounts, round, precision).
Table of Contents
Constants
- RESULT_MODE_COMPONENT = 1
- RESULT_MODE_RAW = 2
Methods
- compare() : bool
- Returns the result of comparing two values with the precision of rounding.
- getConfig() : array<string|int, mixed>
- Returns current calculation settings.
- getCurrency() : string
- Returns result calculation currency.
- getPrecision() : int
- Returns calculation precision.
- getResultMode() : mixed
- isAllowedUseDiscounts() : bool
- Returns true if allowed use discounts.
- isComponentResultMode() : mixed
- isIncludingVat() : bool
- Returns true if result price with VAT.
- isRawResultMode() : mixed
- popConfig() : void
- Set the calculation settings from the stack, if it is not empty.
- pushConfig() : void
- Save current calculation settings to the stack before the changes.
- roundPrecision() : float
- Rounding the price or discount to a specified number of decimal places.
- setConfig() : void
- Set calculation settings.
Constants
RESULT_MODE_COMPONENT
public
mixed
RESULT_MODE_COMPONENT
= 1
RESULT_MODE_RAW
public
mixed
RESULT_MODE_RAW
= 2
Methods
compare()
Returns the result of comparing two values with the precision of rounding.
public
static compare(float|int $firstValue, float|int $secondValue, string $operator) : bool
Parameters
- $firstValue : float|int
-
First value.
- $secondValue : float|int
-
Second value.
- $operator : string
-
Compare operator ( >, >=, <, <=, ==, !=).
Return values
boolgetConfig()
Returns current calculation settings.
public
static getConfig() : array<string|int, mixed>
Return values
array<string|int, mixed>getCurrency()
Returns result calculation currency.
public
static getCurrency() : string
Return values
stringgetPrecision()
Returns calculation precision.
public
static getPrecision() : int
Return values
intgetResultMode()
public
static getResultMode() : mixed
isAllowedUseDiscounts()
Returns true if allowed use discounts.
public
static isAllowedUseDiscounts() : bool
Return values
boolisComponentResultMode()
public
static isComponentResultMode() : mixed
isIncludingVat()
Returns true if result price with VAT.
public
static isIncludingVat() : bool
Return values
boolisRawResultMode()
public
static isRawResultMode() : mixed
popConfig()
Set the calculation settings from the stack, if it is not empty.
public
static popConfig() : void
pushConfig()
Save current calculation settings to the stack before the changes.
public
static pushConfig() : void
roundPrecision()
Rounding the price or discount to a specified number of decimal places.
public
static roundPrecision(float|int $value) : float
Parameters
- $value : float|int
-
Value for rounding.
Return values
floatsetConfig()
Set calculation settings.
public
static setConfig(array<string|int, mixed> $config) : void
Parameters
- $config : array<string|int, mixed>
-
keys are case sensitive:
- string CURRENCY Result currency (can be null - use base currency (compatibility only)).
- int PRECISION Calculation precision (can be null - use default catalog precision - CATALOG_VALUE_PRECISION).
- bool USE_DISCOUNTS Use discounts for calculation (by default use discounts is allowed).
- bool RESULT_WITH_VAT Returns result price without/with VAT (by default return price with VAT).
- int RESULT_MODE Returns raw result for provider or prepared result for components (by default - for components).