CoolCMS API

Cart extends BaseComponent
in package
uses CartPreviewTrait, CheckoutErrorTrait, FormTrait

FinalYes

Renders the cart contents.

The cart reserves nothing: it only shows current availability so that the customer is not rejected after submitting the order (reservations are strict). Prices and totals are computed only by the server (api/eshop/order/checkout, persist = false); the component keeps just setId, quantity and voucher codes in the session.

Table of Contents

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
$preview  : array<string, mixed>|null
Api preview, filled by `render()` and shared by submit handlers for messages.
$productSetManager  : ProductSetManager

Methods

__call()  : mixed
Dispatches `renderXyz()` to `render('Xyz', ...$args)`.
__construct()  : mixed
createComponent()  : IComponent|null
getAppContext()  : AppContext
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
getSettingContext()  : SettingContext
getSettings()  : array<int, array<string, mixed>>
getThemeContext()  : ThemeContext|null
handleDecrease()  : void
handleIncrease()  : void
handleRemove()  : void
handleRemoveVoucher()  : void
hasServiceByType()  : bool
Returns whether the container has a service of the given type.
initializeAllContexts()  : void
injectDeviceDetector()  : void
onCreate()  : void
onSuccess()  : void
render()  : void
setAppContext()  : $this
setComponentParameter()  : void
Sets a component parameter.
setCurrencyContext()  : $this
setLanguageContext()  : $this
setLocalizationContext()  : $this
setSettingContext()  : $this
setThemeContext()  : $this
setup()  : void
setupAppContext()  : void
typedComponent()  : T
Returns a subcomponent with a verified type.
createComponentForm()  : Form
frontPresenter()  : BasePresenter|null
Returns the front presenter the component is attached to (null outside the front end or when detached).
getTranslator()  : ITranslator
setTemplateFile()  : void
setTranslator()  : self
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()}).
applyQuantities()  : void
Stores quantities of all rows (read from the controls, see the trait docblock).
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.
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).
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).
flash()  : void
hasUnavailableRow()  : bool
Returns whether anything in the cart blocks submitting the order.
int()  : int
isSubmittedBy()  : bool
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
redirectBack()  : void
removeSelectedRows()  : void
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.
submitVoucher()  : void
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.

Properties

$componentParameters

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

component parameters set by setComponentParameter()

$translatorDomain

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

$preview

Api preview, filled by `render()` and shared by submit handlers for messages.

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

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>

createComponent()

public createComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|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

getSettings()

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

handleDecrease()

public handleDecrease(int $setId) : void
Parameters
$setId : int

handleIncrease()

public handleIncrease(int $setId) : void
Parameters
$setId : int

handleRemove()

public handleRemove(int $setId) : void
Parameters
$setId : int

handleRemoveVoucher()

public handleRemoveVoucher(string $code) : void
Parameters
$code : string

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

render()

public render([string $style = 'list' ]) : void
Parameters
$style : string = 'list'

setComponentParameter()

Sets a component parameter.

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

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

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

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

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
bool

applyQuantities()

Stores quantities of all rows (read from the controls, see the trait docblock).

private applyQuantities(Form $form) : void
Parameters
$form : Form

blockedSetIds()

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

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

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

flash()

private flash(string $key, string $type) : void
Parameters
$key : string
$type : string

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
bool

int()

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

isSubmittedBy()

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

loadPreview()

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

redirectBack()

private redirectBack() : void

removeSelectedRows()

private removeSelectedRows(Form $form) : void
Parameters
$form : Form

rowFees()

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
string

unpricedItems()

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
Return values
bool|null
On this page

Search results