CartPreviewTrait uses trait:short
Recalculates the cart and composes rows for display, shared by the full cart ({@see \App\UI\Front\Eshop\Components\CartComponent\Cart}) and the header mini cart ({@see \App\UI\Front\Eshop\Components\CartWidgetComponent\CartWidget}).
IMPORTANT: prices are computed only by the server (api/eshop/order/checkout,
persist = false). No price, rate or discount comes from the browser; the cart keeps only
setId, quantity and voucher codes in the session. There must be no arithmetic over a price
from the request here; the only multiplication (bcmul) uses the unit price from the Api
response, not from input.
The trait expects three managers in the host component (promoted private properties):
$cart (CartManager),
$checkoutManager (CheckoutManager) and
$productSetManager (ProductSetManager).
Table of Contents
Constants
- CHECKOUT_REGION_KEY : string = 'paymentRegionId'
- CHECKOUT_REGION_LOCALIZATION_KEY : string = 'paymentRegionLocalizationId'
Properties
- $checkoutRegionCache : PaymentRegion|null
- $checkoutRegionResolved : bool
- $preview : array<string, mixed>|null
- Api preview, filled by `render()` and shared by submit handlers for messages.
Methods
- getCheckoutCurrency() : Currency|null
- Exposes the order currency for the cart and order presenter, which passes it as the page currency (`CurrencyContext::setPageCurrency()`) so that front end JS formats in the same currency.
- checkoutCurrency() : Currency|null
- Returns the cart or order currency, the currency of the region from {@see checkoutRegion()}.
- checkoutRegion() : PaymentRegion|null
- Returns the region by which the cart and order are computed.
- checkoutRegionName() : string
- Returns the region name in the website language (fallback `#id`).
- checkoutRegionNotice() : array{region: string, currency: string, currencyChanged: bool}|null
- Returns the recalculation notice data; null when the cart computes in the localization region, otherwise the chosen region name and currency (the template builds a sentence from them).
- resetCheckoutRegion() : void
- Forgets the resolved region (after a new choice is stored within the same request).
- allowsOutOfStockOrder() : bool
- Returns whether goods that are not in stock may be ordered (`order.outOfStock.allowed`); the same gate as in the catalog ({@see \App\UI\Front\Eshop\Presenters\Traits\Inits\CatalogOnlyGuardTrait::allowsOutOfStockOrder()}).
- blockedSetIds() : array<int, int>
- Returns the set ids that block the continue-to-order button: rows the stock does not cover in the requested quantity (or that cannot be ordered at all) and sets without a price in the cart currency, which only the server preview knows (otherwise they would reach checkout and fail with a generic error). The server strict reservation on submit remains the last authority.
- buildRows() : array<int, array<string, mixed>>
- Merges session rows (setId and quantity) with preview data (name, price, uncovered stock) and catalog availability.
- checkoutCurrencies() : array<int, Currency>
- hasUnavailableRow() : bool
- Returns whether anything in the cart blocks submitting the order.
- int() : int
- loadPreview() : array<string, mixed>
- Returns the Api preview, computed once per request and shared by `render()` and handlers (otherwise the same recalculation would run twice).
- num() : numeric-string
- requestedCheckoutRegionId() : int|null
- rowFees() : array<int, array{name: string, price: numeric-string}>
- Returns informational row fees in the display price column (see `buildRows()`).
- str() : string
- DBAL/Api scalar (mixed) → string, guarded.
- unpricedItems() : array<int, string>
- Returns sets the Api omitted from the preview because they have no price in the cart currency.
- vatNoteMode() : bool|null
- Returns the VAT note variant for cart templates: `null` means the order charges no VAT and VAT is not mentioned; `true` means prices are shown with VAT. The Api sends `showPricesWithVat` equal to `withVat` (the VAT engine treatment; the seller switch `show_prices_with_vat` is no longer read), so `false` does not occur today. A preview without an Api response gives `null`, because silence is safer than a false claim.
Constants
CHECKOUT_REGION_KEY
public
string
CHECKOUT_REGION_KEY
= 'paymentRegionId'
CHECKOUT_REGION_LOCALIZATION_KEY
public
string
CHECKOUT_REGION_LOCALIZATION_KEY
= 'paymentRegionLocalizationId'
Properties
$checkoutRegionCache
private
PaymentRegion|null
$checkoutRegionCache
= null
$checkoutRegionResolved
private
bool
$checkoutRegionResolved
= false
$preview
Api preview, filled by `render()` and shared by submit handlers for messages.
private
array<string, mixed>|null
$preview
= null
Methods
getCheckoutCurrency()
Exposes the order currency for the cart and order presenter, which passes it as the page currency (`CurrencyContext::setPageCurrency()`) so that front end JS formats in the same currency.
public
getCheckoutCurrency() : Currency|null
Return values
Currency|nullcheckoutCurrency()
Returns the cart or order currency, the currency of the region from {@see checkoutRegion()}.
protected
checkoutCurrency() : Currency|null
Return values
Currency|nullcheckoutRegion()
Returns the region by which the cart and order are computed.
protected
checkoutRegion() : PaymentRegion|null
Return values
PaymentRegion|nullcheckoutRegionName()
Returns the region name in the website language (fallback `#id`).
protected
checkoutRegionName(PaymentRegion|null $region) : string
Parameters
- $region : PaymentRegion|null
Return values
stringcheckoutRegionNotice()
Returns the recalculation notice data; null when the cart computes in the localization region, otherwise the chosen region name and currency (the template builds a sentence from them).
protected
checkoutRegionNotice() : array{region: string, currency: string, currencyChanged: bool}|null
Return values
array{region: string, currency: string, currencyChanged: bool}|nullresetCheckoutRegion()
Forgets the resolved region (after a new choice is stored within the same request).
protected
resetCheckoutRegion() : void
allowsOutOfStockOrder()
Returns whether goods that are not in stock may be ordered (`order.outOfStock.allowed`); the same gate as in the catalog ({@see \App\UI\Front\Eshop\Presenters\Traits\Inits\CatalogOnlyGuardTrait::allowsOutOfStockOrder()}).
private
allowsOutOfStockOrder() : bool
A missing key means disabled.
Return values
boolblockedSetIds()
Returns the set ids that block the continue-to-order button: rows the stock does not cover in the requested quantity (or that cannot be ordered at all) and sets without a price in the cart currency, which only the server preview knows (otherwise they would reach checkout and fail with a generic error). The server strict reservation on submit remains the last authority.
private
blockedSetIds(array<int, array{setId: int, quantity: int}> $lines) : array<int, int>
Parameters
- $lines : array<int, array{setId: int, quantity: int}>
Return values
array<int, int> —setIds of blocking rows
buildRows()
Merges session rows (setId and quantity) with preview data (name, price, uncovered stock) and catalog availability.
private
buildRows(array<int, array{setId: int, quantity: int}> $lines, array<string, mixed>|null $order) : array<int, array<string, mixed>>
A row unknown to the Api (a deleted set) is kept with an empty price, because the customer
must see it to be able to remove it. unitPriceDisplay and totalPriceDisplay carry the
display price: the order snapshot has both (price is the base, priceWithVat includes
VAT; identical for a non-payer) and vatNoteMode() picks the column. Cart summaries
do not follow it; they always show the amount actually paid (*WithVat).
Parameters
- $lines : array<int, array{setId: int, quantity: int}>
- $order : array<string, mixed>|null
Return values
array<int, array<string, mixed>>checkoutCurrencies()
private
checkoutCurrencies() : array<int, Currency>
Return values
array<int, Currency>hasUnavailableRow()
Returns whether anything in the cart blocks submitting the order.
private
hasUnavailableRow(array<int, array<string, mixed>> $rows) : bool
It is computed from the composed rows (buildRows()), not from the Api response: besides
goods without a stock card (notInStock) it covers plain sell-out, which the Api preview does
not know (the cart reserves nothing). Without it the customer would reach checkout and be
rejected only by the strict reservation, with no explanation.
Parameters
- $rows : array<int, array<string, mixed>>
Return values
boolint()
private
int(mixed $value) : int
Parameters
- $value : mixed
Return values
intloadPreview()
Returns the Api preview, computed once per request and shared by `render()` and handlers (otherwise the same recalculation would run twice).
private
loadPreview() : array<string, mixed>
Return values
array<string, mixed>num()
private
num(mixed $value) : numeric-string
Parameters
- $value : mixed
Return values
numeric-stringrequestedCheckoutRegionId()
private
requestedCheckoutRegionId() : int|null
Return values
int|nullrowFees()
Returns informational row fees in the display price column (see `buildRows()`).
private
rowFees(array<string, mixed>|null $item, string $priceKey) : array<int, array{name: string, price: numeric-string}>
Parameters
- $item : array<string, mixed>|null
- $priceKey : string
Return values
array<int, array{name: string, price: numeric-string}>str()
DBAL/Api scalar (mixed) → string, guarded.
private
str(mixed $value) : string
Parameters
- $value : mixed
Return values
stringunpricedItems()
Returns sets the Api omitted from the preview because they have no price in the cart currency.
private
unpricedItems(array<string|int, mixed>|null $order) : array<int, string>
Parameters
- $order : array<string|int, mixed>|null
Return values
array<int, string> —setId mapped to the set name
vatNoteMode()
Returns the VAT note variant for cart templates: `null` means the order charges no VAT and VAT is not mentioned; `true` means prices are shown with VAT. The Api sends `showPricesWithVat` equal to `withVat` (the VAT engine treatment; the seller switch `show_prices_with_vat` is no longer read), so `false` does not occur today. A preview without an Api response gives `null`, because silence is safer than a false claim.
private
vatNoteMode(array<string, mixed>|null $order) : bool|null
Parameters
- $order : array<string, mixed>|null