ShippingPriceResolver
in package
Resolves the currently valid shipping price of a tariff for a given total weight.
Reads the append-only time series cms_mod_eshop_shipper_tariff_prices directly (no view).
A band matches when weight_from <= w, weight_to IS NULL OR weight_to >= w (edges are
inclusive) and date_from <= $at; the freshest date_from per tariff wins. Planned future
price tables therefore stay excluded until their date_from arrives, without any cron. On equal
date_from the lowest price wins.
A null weight_to is an open-ended band with no ceiling. A generation may hold at most one
such band and it must have the highest weight_from (enforced by the admin form), so null
never overlaps a finite band below it.
?DateTimeInterface $at is a parameter, not a baked-in NOW(): the order snapshot builder
takes the time once and passes it through every resolver (product, shipping, payment).
With separate NOW() calls an order processed exactly at a generation boundary could mix an
old product price with a new shipping price and the order total would not add up.
Uses raw DBAL (IN (?) batch), not Doctrine find(), like PriceResolver. Weights are
decimal strings: comparisons happen in SQL (exact decimal, no float rounding) and PHP-side
amounts (weight totals, free_from threshold) go through bcmath.
IMPORTANT: the total order weight is the sum of item weight times quantity, never just the sum of weights; calculateTotalWeight() is the single place to compute it.
Table of Contents
Constants
- DECIMAL_SCALE : int = 3
- TABLE : string = 'cms_mod_eshop_shipper_tariff_prices'
Properties
- $em : EntityManagerInterface
Methods
- __construct() : mixed
- calculateTotalWeight() : string
- Computes the total order weight as the sum of weight times quantity, for tariff selection.
- resolve() : ShippingPriceResult|null
- resolveBatch() : array<int, ShippingPriceResult>
- Batch resolve: one SQL for N tariffs (e.g. listing all shipping options at checkout).
- applyFreeFrom() : array{0: bool, 1: string}
- buildResult() : ShippingPriceResult
- normalizeDecimal() : numeric-string
- toInt() : int
- toStr() : string
Constants
DECIMAL_SCALE
private
int
DECIMAL_SCALE
= 3
TABLE
private
string
TABLE
= 'cms_mod_eshop_shipper_tariff_prices'
Properties
$em read-only
private
EntityManagerInterface
$em
Methods
__construct()
public
__construct(EntityManagerInterface $em) : mixed
Parameters
- $em : EntityManagerInterface
calculateTotalWeight()
Computes the total order weight as the sum of weight times quantity, for tariff selection.
public
calculateTotalWeight(array<int, array{weight: string, quantity: int|string}> $items) : string
Single place for this computation (a plain sum of weights would ignore quantity).
Parameters
- $items : array<int, array{weight: string, quantity: int|string}>
Return values
stringresolve()
public
resolve(int $tariffId, int $currencyId, string $totalWeight[, string|null $cartTotal = null ][, DateTimeInterface|null $at = null ]) : ShippingPriceResult|null
Parameters
- $tariffId : int
- $currencyId : int
- $totalWeight : string
- $cartTotal : string|null = null
- $at : DateTimeInterface|null = null
-
time of validity; null means now. The order snapshot builder passes one shared instant into every resolver so a checkout at a generation boundary cannot mix an old product price with a new shipping price.
Return values
ShippingPriceResult|nullresolveBatch()
Batch resolve: one SQL for N tariffs (e.g. listing all shipping options at checkout).
public
resolveBatch(array<string|int, int> $tariffIds, int $currencyId, string $totalWeight[, string|null $cartTotal = null ][, DateTimeInterface|null $at = null ]) : array<int, ShippingPriceResult>
Parameters
- $tariffIds : array<string|int, int>
- $currencyId : int
- $totalWeight : string
- $cartTotal : string|null = null
- $at : DateTimeInterface|null = null
-
time of validity; null means now (see resolve())
Return values
array<int, ShippingPriceResult> —keyed by tariffId (tariffs without a matching band/currency/date are simply absent)
applyFreeFrom()
private
applyFreeFrom(string $price, string|null $freeFrom, string|null $cartTotal) : array{0: bool, 1: string}
Parameters
- $price : string
- $freeFrom : string|null
- $cartTotal : string|null
Return values
array{0: bool, 1: string} —[isFree, priceAfterFreeFrom]
buildResult()
private
buildResult(array<string, mixed> $row, int $tariffId, string|null $cartTotal) : ShippingPriceResult
Parameters
- $row : array<string, mixed>
- $tariffId : int
- $cartTotal : string|null
Return values
ShippingPriceResultnormalizeDecimal()
private
normalizeDecimal(string $value) : numeric-string
Parameters
- $value : string
Return values
numeric-stringtoInt()
private
toInt(mixed $value) : int
Parameters
- $value : mixed
Return values
inttoStr()
private
toStr(mixed $value) : string
Parameters
- $value : mixed