CoolCMS API

PriceDisplayHelper
in package

FinalYes

Computes the price to display on the front end.

The e-shop price list is always the base without VAT. Whether the front end shows the price with VAT is decided by chargeVat of the VAT engine (bridge actions api/eshop/product-set/price-display / .../current-prices); sellers.show_prices_with_vat is no longer read, a VAT payer always shows the price with VAT.

Rule:

  • non-payer (chargeVat=false): the base is shown and VAT is mentioned nowhere,
  • payer (chargeVat=true): base * (1 + rate) is shown, texts say "including VAT".

The arithmetic deliberately matches OrderCalculator::withVat() (bcmath, intermediate scale 6, round3 half-up), so the displayed price equals to the cent the one checkout computes for the order. Pure helper without I/O, hence static (like ProductSetEligibilityFilters).

Table of Contents

Constants

SCALE  : int = 3
Output precision; must match `OrderCalculator::SCALE`.
WORK_SCALE  : int = 6
Intermediate precision; must match `OrderCalculator::WORK_SCALE`.

Methods

display()  : string|null
Returns the display price from a base and a rate. `$withVat = false` returns the base unchanged; a `null` input stays `null` (a "price on request" must not be created by the calculation).
vatNoteMode()  : bool|null
Returns the VAT note variant for templates: `null` = non-payer, VAT is not mentioned; `true` = payer showing prices with VAT; `false` = payer showing the base.
withVat()  : numeric-string
Returns the base plus VAT (round3 half-up); mirrors `OrderCalculator::withVat()`.
withVatIf()  : string
Like {@see self::display()} but for a non-nullable base (always returns a string).
norm()  : numeric-string
round3()  : numeric-string

Constants

SCALE

Output precision; must match `OrderCalculator::SCALE`.

private int SCALE = 3

WORK_SCALE

Intermediate precision; must match `OrderCalculator::WORK_SCALE`.

private int WORK_SCALE = 6

Methods

display()

Returns the display price from a base and a rate. `$withVat = false` returns the base unchanged; a `null` input stays `null` (a "price on request" must not be created by the calculation).

public static display(string|null $base, string $vatPercents, bool $withVat) : string|null
Parameters
$base : string|null
$vatPercents : string
$withVat : bool
Return values
string|null

vatNoteMode()

Returns the VAT note variant for templates: `null` = non-payer, VAT is not mentioned; `true` = payer showing prices with VAT; `false` = payer showing the base.

public static vatNoteMode(bool $sellerUseVat, bool $showPricesWithVat) : bool|null
Parameters
$sellerUseVat : bool
$showPricesWithVat : bool
Return values
bool|null

withVat()

Returns the base plus VAT (round3 half-up); mirrors `OrderCalculator::withVat()`.

public static withVat(string $base, string $vatPercents) : numeric-string
Parameters
$base : string
$vatPercents : string
Return values
numeric-string

withVatIf()

Like {@see self::display()} but for a non-nullable base (always returns a string).

public static withVatIf(string $base, string $vatPercents, bool $withVat) : string
Parameters
$base : string
$vatPercents : string
$withVat : bool
Return values
string

norm()

private static norm(string $value) : numeric-string
Parameters
$value : string
Return values
numeric-string

round3()

private static round3(numeric-string $value) : numeric-string
Parameters
$value : numeric-string
Return values
numeric-string
On this page

Search results