CoolCMS API

Checkout extends BaseComponent
in package
uses AddressFormTrait, RegionFormTrait, CheckoutRegionTrait, ShippingFormTrait, SummaryFormTrait, CheckoutErrorTrait

FinalYes

Renders the order steps.

  1. Address: billing data, company purchase and VAT payer, delivery address.
  2. Shipping and payment: one screen, because the payment price list is a matrix of tariff, method and currency and a payment price cannot be computed without a tariff.
  3. Summary: recap plus the binding submit with a one-time token.

Unfinished steps are kept in the session (CartManager); the order is stored only by step 3, in a single api/eshop/order/checkout call with persist = true.

IMPORTANT: neither the client nor the component computes prices; every recalculation goes to the server (persist = false), so the screen always shows what will actually be stored.

Table of Contents

Constants

CHECKOUT_REGION_KEY  : string = 'paymentRegionId'
CHECKOUT_REGION_LOCALIZATION_KEY  : string = 'paymentRegionLocalizationId'
STEP_ADDRESS  : int = 1
STEP_SHIPPING  : int = 2
STEP_SUMMARY  : int = 3

Properties

$container  : Container
$routerDispatcher  : RouterDispatcher
$translator  : ITranslator
$appContext  : AppContext
$componentParameters  : array<string, mixed>
$currencyContext  : CurrencyContext|null
$deviceDetector  : DeviceDetector|null
$languageContext  : LanguageContext|null
$localizationContext  : LocalizationContext|null
$settingContext  : SettingContext
$themeContext  : ThemeContext|null
$translatorDomain  : string|null
$cart  : CartManager
$checkoutManager  : CheckoutManager
$checkoutRegionCache  : PaymentRegion|null
$checkoutRegionResolved  : bool
$countryManager  : CountryManager
$preview  : array<string, mixed>|null
Api preview, computed once per request (shared by render and handlers).
$step  : int
$userManager  : UserManager

Methods

__call()  : mixed
Dispatches `renderXyz()` to `render('Xyz', ...$args)`.
__construct()  : mixed
buildPayload()  : array<string, mixed>
Builds the Api payload: only identifiers and customer-entered texts, never a price, rate or discount.
createComponent()  : IComponent|null
getAppContext()  : AppContext
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.
getComponentParameter()  : mixed
Returns a component parameter, or null when it is not set.
getContainer()  : Container
getCurrencyContext()  : CurrencyContext|null
getLanguageContext()  : LanguageContext|null
getLocalizationContext()  : LocalizationContext|null
getRouterDispatcher()  : RouterDispatcher
getSelectedBranchId()  : int|null
getSelectedPaymentMethodId()  : int|null
getSelectedTariffId()  : int|null
Returns the selected tariff id, read from POST data first and from the session second.
getSettingContext()  : SettingContext
getSettings()  : array<int, array<string, mixed>>
getStep()  : int
getThemeContext()  : ThemeContext|null
hasServiceByType()  : bool
Returns whether the container has a service of the given type.
hasUnpricedItems()  : bool
Returns whether the cart has a set without a price in the cart currency.
initializeAllContexts()  : void
injectDeviceDetector()  : void
invalidatePreview()  : void
Forces a new recalculation after an input change (AJAX auto-update of step 2).
isStepReachable()  : bool
A step is reachable only when all previous steps are filled in (guard in the presenter).
loadPreview()  : array<string, mixed>
Returns the order preview for the steps filled in so far.
onAddressSuccess()  : void
onCreate()  : void
onRegionSuccess()  : void
onShippingSubmit()  : void
Handles AJAX auto-update: stores the unfinished choice, drops the preview and redraws the snippet.
onShippingSuccess()  : void
onSummarySuccess()  : void
render()  : void
setAppContext()  : $this
setComponentParameter()  : void
Sets a component parameter.
setCurrencyContext()  : $this
setLanguageContext()  : $this
setLocalizationContext()  : $this
setSettingContext()  : $this
setStep()  : self
setThemeContext()  : $this
setup()  : void
setupAppContext()  : void
summaryRows()  : array<int, array<string, mixed>>
typedComponent()  : T
Returns a subcomponent with a verified type.
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).
createComponentAddressForm()  : Form
createComponentRegionForm()  : Form
createComponentShippingForm()  : Form
createComponentSummaryForm()  : Form
frontPresenter()  : BasePresenter|null
Returns the front presenter the component is attached to (null outside the front end or when detached).
getTranslator()  : ITranslator
resetCheckoutRegion()  : void
Forgets the resolved region (after a new choice is stored within the same request).
setTemplateFile()  : void
setTranslator()  : self
applyUserAccountFallback()  : void
Prefills defaults for a logged-in customer: unfinished checkout first, then the account.
boolValue()  : bool
branchItems()  : array<int, string>
Returns branches (`shipper_tariff_branches`) of the selected tariff.
checkoutCurrencies()  : array<int, Currency>
checkoutCurrencyShortcut()  : string
checkoutErrorFlash()  : Message
Returns the same message for a flash; a flash is translated only in the layout, so it carries the key with parameters.
checkoutErrorText()  : string
Returns the translated text for direct output in the template (the preview error bar).
checkoutInt()  : int|null
Reads the value only from the unfinished checkout in the session (no POST); see {@see buildPayload()}.
controlString()  : string
countryOptions()  : array<string, string>
Returns country options for the select (active countries, CZ and SK first; {@see \App\Core\Utils\Helpers\CountryOptionsHelper}).
createMultiplierComponent()  : Multiplier<string|int, IComponent>
Creates a multiplier for the component.
createNewComponentInstance()  : IComponent|null
Creates a new component instance without adding it to the presenter; used by the multiplier.
createStandardComponent()  : IComponent|null
Creates a standard component (not a multiplier).
decodePickupPoint()  : array<string, mixed>|null
Decodes the raw JSON from the `pickupPoint` hidden field into an associative array.
goToStep()  : void
handlePlaceFailure()  : void
isPickupPointMissing()  : bool
Returns whether the selected tariff requires a pickup point that is missing in the unfinished checkout.
offeredId()  : int|null
Returns the id when it is among the items, otherwise null.
optionInt()  : int
optionRows()  : array<int, array<string, mixed>>
Returns offer rows from the Api response.
optionStr()  : string
persistShippingSelection()  : void
pickupInfo()  : array{requiresPickup: bool, widget: array|null}|null
Returns the pickup point info of the selected tariff.
pickupPointJson()  : string
Encodes the point back for the hidden field `setDefaults()`; the exact opposite of {@see decodePickupPoint()}.
postOrCheckoutInt()  : int|null
redirectToDone()  : void
regionItems()  : array<int, string>
Returns usable regions (active, with an active non-internal currency) as "Name (currency)".
requestedCheckoutRegionId()  : int|null
setAddressDefaults()  : void
shippingOptions()  : array{shipping: list>, payment: list>}
stringKeyed()  : array<string, mixed>
Narrows `array<mixed, mixed>` to `array<string, mixed>`.
strValue()  : string
summaryStr()  : string
translatePrompt()  : string
Translates a text for a control with a disabled translator (the country select).

Constants

CHECKOUT_REGION_LOCALIZATION_KEY

public string CHECKOUT_REGION_LOCALIZATION_KEY = 'paymentRegionLocalizationId'

STEP_ADDRESS

public int STEP_ADDRESS = 1

STEP_SHIPPING

public int STEP_SHIPPING = 2

STEP_SUMMARY

public int STEP_SUMMARY = 3

Properties

$componentParameters

protected array<string, mixed> $componentParameters = []

component parameters set by setComponentParameter()

$translatorDomain

protected string|null $translatorDomain = 'front.eshop.components.checkout'

$preview

Api preview, computed once per request (shared by render and handlers).

private array<string, mixed>|null $preview = null

$step

private int $step = self::STEP_ADDRESS

Methods

__call()

Dispatches `renderXyz()` to `render('Xyz', ...$args)`.

public __call(string $name, array<string|int, mixed> $args) : mixed

Called only when the component has no renderXyz() method of its own.

Parameters
$name : string
$args : array<string|int, mixed>

buildPayload()

Builds the Api payload: only identifiers and customer-entered texts, never a price, rate or discount.

public buildPayload([bool $bindingSubmit = false ]) : array<string, mixed>

With $bindingSubmit = true (binding submit, step 3) shipping, payment and branch come only from the session, never from POST; see postOrCheckoutInt(). The recap is built from the session, so the customer must order exactly what they saw. The step 3 POST carries none of those fields, so their presence would mean a mismatch between the recap and the order.

Parameters
$bindingSubmit : bool = false
Return values
array<string, mixed>

createComponent()

public createComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

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|null

getComponentParameter()

Returns a component parameter, or null when it is not set.

public getComponentParameter(string $name) : mixed
Parameters
$name : string

getContainer()

public getContainer() : Container
Return values
Container

getSelectedBranchId()

public getSelectedBranchId() : int|null
Return values
int|null

getSelectedPaymentMethodId()

public getSelectedPaymentMethodId() : int|null
Return values
int|null

getSelectedTariffId()

Returns the selected tariff id, read from POST data first and from the session second.

public getSelectedTariffId() : int|null

IMPORTANT: without this the step 2 form (and its preview) would be built from the old tariff. A customer without JS picks another carrier and payment in one submit, but the payment radio list items would come from the previous tariff and Nette would reject the submitted value as invalid. The same applies to the other selected ids below.

Return values
int|null

getSettings()

public getSettings() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>

getStep()

public getStep() : int
Return values
int

hasServiceByType()

Returns whether the container has a service of the given type.

public hasServiceByType(string $className) : bool

The name is composed dynamically (module plus component), so class_exists() runs first, and a true result guarantees a valid type.

Parameters
$className : string
Tags
phpstan-assert-if-true

class-string $className

Return values
bool

hasUnpricedItems()

Returns whether the cart has a set without a price in the cart currency.

public hasUnpricedItems() : bool

The server preview (unpricedItems) decides; the presenter calls it before entering the order steps.

Return values
bool

invalidatePreview()

Forces a new recalculation after an input change (AJAX auto-update of step 2).

public invalidatePreview() : void

isStepReachable()

A step is reachable only when all previous steps are filled in (guard in the presenter).

public isStepReachable(int $step) : bool
Parameters
$step : int
Return values
bool

loadPreview()

Returns the order preview for the steps filled in so far.

public loadPreview() : array<string, mixed>

tariffId and paymentMethodId come from the unfinished checkout, so step 2 sees payment prices for the selected tariff and step 3 sees the final totals.

Return values
array<string, mixed>

onShippingSubmit()

Handles AJAX auto-update: stores the unfinished choice, drops the preview and redraws the snippet.

public onShippingSubmit(Form $form) : void

Runs before validation, so an incomplete choice (shipping only) breaks nothing.

Parameters
$form : Form

render()

public render([string|null $style = null ]) : void
Parameters
$style : string|null = null

setComponentParameter()

Sets a component parameter.

public setComponentParameter(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed

setStep()

public setStep(int $step) : self
Parameters
$step : int
Return values
self

summaryRows()

public summaryRows() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>> —

recap rows for the template

typedComponent()

Returns a subcomponent with a verified type.

public typedComponent(string $name, T> $type) : T

Use it instead of an inline @var above $this['x'] (which does not narrow the type) and instead of the generic IComponent that $this['x'] returns. See Form::typedComponent().

Parameters
$name : string
$type : T>
Tags
template
Return values
T

checkoutCurrency()

Returns the cart or order currency, the currency of the region from {@see checkoutRegion()}.

protected checkoutCurrency() : Currency|null
Return values
Currency|null

checkoutRegionName()

Returns the region name in the website language (fallback `#id`).

protected checkoutRegionName(PaymentRegion|null $region) : string
Parameters
$region : PaymentRegion|null
Return values
string

checkoutRegionNotice()

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}|null

frontPresenter()

Returns the front presenter the component is attached to (null outside the front end or when detached).

protected frontPresenter() : BasePresenter|null
Return values
BasePresenter|null

getTranslator()

protected getTranslator() : ITranslator
Return values
ITranslator

resetCheckoutRegion()

Forgets the resolved region (after a new choice is stored within the same request).

protected resetCheckoutRegion() : void

setTemplateFile()

protected setTemplateFile(string $dir, string $filename) : void
Parameters
$dir : string
$filename : string

setTranslator()

protected setTranslator(ITranslator $translator) : self
Parameters
$translator : ITranslator
Return values
self

applyUserAccountFallback()

Prefills defaults for a logged-in customer: unfinished checkout first, then the account.

private applyUserAccountFallback(array<string, mixed> &$defaults) : void

What the customer already filled in (held by the unfinished checkout in the session or DB per %eshop.cart.storage%) is never overwritten; only empty fields are filled from the account. The order is a snapshot, so the user profile is not changed.

NOTE: only fields stored on the user account (cms_system_users) are used; contacts of the Invoicer (CustomerContact matched by e-mail) are not, because that would need a choice among several saved addresses.

Parameters
$defaults : array<string, mixed>

boolValue()

private boolValue(Form $form, string $name) : bool
Parameters
$form : Form
$name : string
Return values
bool

branchItems()

Returns branches (`shipper_tariff_branches`) of the selected tariff.

private branchItems(array<int, array<string, mixed>> $shipping, int|null $tariffId) : array<int, string>

A tariff without branches yields an empty array, so the select is not rendered and not required.

Parameters
$shipping : array<int, array<string, mixed>>
$tariffId : int|null
Return values
array<int, string>

checkoutCurrencyShortcut()

private checkoutCurrencyShortcut() : string
Return values
string

checkoutErrorFlash()

Returns the same message for a flash; a flash is translated only in the layout, so it carries the key with parameters.

private checkoutErrorFlash(array<string, mixed> $result) : Message
Parameters
$result : array<string, mixed>
Return values
Message

checkoutErrorText()

Returns the translated text for direct output in the template (the preview error bar).

private checkoutErrorText(array<string, mixed> $result) : string
Parameters
$result : array<string, mixed>
Return values
string

checkoutInt()

Reads the value only from the unfinished checkout in the session (no POST); see {@see buildPayload()}.

private checkoutInt(string $key) : int|null
Parameters
$key : string
Return values
int|null

controlString()

private controlString(Form $form, string $name) : string
Parameters
$form : Form
$name : string
Return values
string

countryOptions()

Returns country options for the select (active countries, CZ and SK first; {@see \App\Core\Utils\Helpers\CountryOptionsHelper}).

private countryOptions() : array<string, string>
Return values
array<string, string>

createMultiplierComponent()

Creates a multiplier for the component.

private createMultiplierComponent(string $name) : Multiplier<string|int, IComponent>
Parameters
$name : string
Return values
Multiplier<string|int, IComponent>

createNewComponentInstance()

Creates a new component instance without adding it to the presenter; used by the multiplier.

private createNewComponentInstance(string $baseName[, int|string|null $uniqueKey = null ]) : IComponent|null
Parameters
$baseName : string
$uniqueKey : int|string|null = null
Return values
IComponent|null

createStandardComponent()

Creates a standard component (not a multiplier).

private createStandardComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

decodePickupPoint()

Decodes the raw JSON from the `pickupPoint` hidden field into an associative array.

private decodePickupPoint(string|null $raw) : array<string, mixed>|null

Invalid JSON, an empty string or anything other than a JSON object yields null (nothing selected; the page must never crash).

Parameters
$raw : string|null
Return values
array<string, mixed>|null

goToStep()

private goToStep(int $step) : void
Parameters
$step : int

handlePlaceFailure()

private handlePlaceFailure(array<string, mixed> $result) : void
Parameters
$result : array<string, mixed>

isPickupPointMissing()

Returns whether the selected tariff requires a pickup point that is missing in the unfinished checkout.

private isPickupPointMissing() : bool

The offer is read from a fresh preview (after persistShippingSelection()), so it applies to the tariff just submitted, not to the one from the previous request.

Return values
bool

offeredId()

Returns the id when it is among the items, otherwise null.

private offeredId(int|null $id, array<int, string> $items) : int|null
Parameters
$id : int|null
$items : array<int, string>
Return values
int|null

optionInt()

private optionInt(mixed $value) : int
Parameters
$value : mixed
Return values
int

optionRows()

Returns offer rows from the Api response.

private optionRows(mixed $rows) : array<int, array<string, mixed>>

Values are mixed, so they are normalized to array<string, mixed> and invalid ones are dropped (the form must not receive half of the data).

Parameters
$rows : mixed
Return values
array<int, array<string, mixed>>

optionStr()

private optionStr(mixed $value) : string
Parameters
$value : mixed
Return values
string

pickupInfo()

Returns the pickup point info of the selected tariff.

private pickupInfo(array<int, array<string, mixed>> $shipping, int|null $tariffId) : array{requiresPickup: bool, widget: array|null}|null

null means the tariff either needs no pickup point or is not in the offer at all (a defense against an invalid POST).

Parameters
$shipping : array<int, array<string, mixed>>
$tariffId : int|null
Return values
array{requiresPickup: bool, widget: array|null}|null

pickupPointJson()

Encodes the point back for the hidden field `setDefaults()`; the exact opposite of {@see decodePickupPoint()}.

private pickupPointJson(mixed $point) : string
Parameters
$point : mixed
Return values
string

postOrCheckoutInt()

private postOrCheckoutInt(string $key) : int|null
Parameters
$key : string
Return values
int|null

redirectToDone()

private redirectToDone(int $orderId, int|null $paymentId) : void
Parameters
$orderId : int
$paymentId : int|null

regionItems()

Returns usable regions (active, with an active non-internal currency) as "Name (currency)".

private regionItems() : array<int, string>
Return values
array<int, string>

requestedCheckoutRegionId()

private requestedCheckoutRegionId() : int|null
Return values
int|null

shippingOptions()

private shippingOptions() : array{shipping: list>, payment: list>}
Return values
array{shipping: list>, payment: list>}

stringKeyed()

Narrows `array<mixed, mixed>` to `array<string, mixed>`.

private stringKeyed(array<string|int, mixed> $value) : array<string, mixed>

The Api sends an associative array with string keys, but PHPStan cannot infer that from is_array() alone.

Parameters
$value : array<string|int, mixed>
Return values
array<string, mixed>

strValue()

private strValue(Form $form, string $name) : string
Parameters
$form : Form
$name : string
Return values
string

summaryStr()

private summaryStr(mixed $value) : string
Parameters
$value : mixed
Return values
string

translatePrompt()

Translates a text for a control with a disabled translator (the country select).

private translatePrompt(string $key) : string
Parameters
$key : string
Return values
string
On this page

Search results