DisplayRegionResolver
in package
Single source of currency and VAT for displaying prices on the website: the payment region.
Catalog, cart and order show prices in the currency of the payment region, not the localization currency. The region is chosen in this order:
- region chosen by the customer in the order (checkout, cart session),
- region of the localization (
/en/gives "EU" andEUR), - first usable default region (
is_default), - first usable region at all.
Usable means an active region with an active, non-internal currency. A region with a disabled or internal currency (credits) would show prices that cannot be paid, so it is skipped.
The class is pure (no DI, no DB); contexts fill it from presenters and checkout. Covered by
tests/Unit/Core/DisplayRegionResolverTest.php.
Table of Contents
Methods
- currencyOf() : Currency|null
- differsFromLocalization() : bool
- Whether the order region differs from the localization region. The customer then has to get a message that the cart was recalculated (another currency or another VAT).
- indexCurrencies() : array<int, Currency>
- Currencies indexed by id (the `findAll()` input is a list).
- isUsable() : bool
- resolve() : PaymentRegion|null
Methods
currencyOf()
public
static currencyOf(PaymentRegion|null $region, array<int, Currency> $currencies) : Currency|null
Parameters
- $region : PaymentRegion|null
- $currencies : array<int, Currency>
Return values
Currency|nulldiffersFromLocalization()
Whether the order region differs from the localization region. The customer then has to get a message that the cart was recalculated (another currency or another VAT).
public
static differsFromLocalization(PaymentRegion|null $effective, PaymentRegion|null $localizationRegion) : bool
Parameters
- $effective : PaymentRegion|null
- $localizationRegion : PaymentRegion|null
Return values
boolindexCurrencies()
Currencies indexed by id (the `findAll()` input is a list).
public
static indexCurrencies(iterable<string|int, mixed> $currencies) : array<int, Currency>
Parameters
- $currencies : iterable<string|int, mixed>
Return values
array<int, Currency>isUsable()
public
static isUsable(PaymentRegion $region, array<int, Currency> $currencies) : bool
Parameters
- $region : PaymentRegion
- $currencies : array<int, Currency>
Return values
boolresolve()
public
static resolve(iterable<string|int, mixed> $regions, array<int, Currency> $currencies, int|null $requestedRegionId, int|null $localizationRegionId) : PaymentRegion|null
Parameters
- $regions : iterable<string|int, mixed>
-
payment regions (other values are ignored)
- $currencies : array<int, Currency>
-
currencies by id
- $requestedRegionId : int|null
- $localizationRegionId : int|null