CoolCMS API

CartRepository extends ApiRepository
in package

FinalYes

Raw access to `api/eshop/cart/*` through `ApiBridge`.

No business logic and no translation to CartSnapshot (done by CartMapper one layer up); it only calls the endpoint, returns the raw response and maintains the stable sessionKey.

ApiBridge lives only here: nothing else in app/UI/Front holds it except repositories (same convention as CheckoutRepository).

Table of Contents

Constants

SESSION_KEY_FIELD  : string = '_dbSessionKey'
SESSION_SECTION  : string = 'eshop.cart'

Properties

$apiEndpoint  : string
Api presenter path (e.g. `api/system/page`); set by each concrete repository.
$bridge  : ApiBridge
$session  : Session

Methods

__construct()  : mixed
find()  : array<string|int, mixed>
findAll()  : array<string|int, mixed>
findBy()  : array<string|int, mixed>
load()  : array<string, mixed>
save()  : array<string, mixed>
failSoftRead()  : array<string|int, mixed>
Normalizes a bridge response to plain data; a failed envelope or a non-array gives `[]`.
getApiCallSource()  : string
Branch marker for writes ({@see ApiBridge::PARAM_SOURCE}), read by the shared repository `SaveTrait`.
sessionKey()  : string
Returns a stable cart key independent of `Session::getId()`.

Constants

SESSION_KEY_FIELD

private string SESSION_KEY_FIELD = '_dbSessionKey'

Properties

$apiEndpoint

Api presenter path (e.g. `api/system/page`); set by each concrete repository.

protected string $apiEndpoint = 'api/eshop/cart'

Methods

find()

public find(int $id[, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
Parameters
$id : int
$includes : string|array<string|int, mixed> = []
$useCache : bool|null = null
Return values
array<string|int, mixed>

findAll()

public findAll([array<string|int, mixed>|null $filters = [] ][, array<string|int, mixed>|null $orderBys = null ][, int|null $offset = null ][, int|null $limit = null ][, array<string|int, mixed>|null $columns = null ][, bool $computeTotalCount = false ][, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
Parameters
$filters : array<string|int, mixed>|null = []
$orderBys : array<string|int, mixed>|null = null
$offset : int|null = null
$limit : int|null = null
$columns : array<string|int, mixed>|null = null
$computeTotalCount : bool = false
$includes : string|array<string|int, mixed> = []
$useCache : bool|null = null
Return values
array<string|int, mixed>

findBy()

public findBy([array<string|int, mixed>|null $filters = [] ][, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
Parameters
$filters : array<string|int, mixed>|null = []
$includes : string|array<string|int, mixed> = []
$useCache : bool|null = null
Return values
array<string|int, mixed>

load()

public load(int|null $userId) : array<string, mixed>
Parameters
$userId : int|null
Return values
array<string, mixed> —

raw response of api/eshop/cart/load

save()

public save(int|null $userId, array<string, mixed> $snapshot) : array<string, mixed>
Parameters
$userId : int|null
$snapshot : array<string, mixed>
Return values
array<string, mixed> —

raw response of api/eshop/cart/save

failSoftRead()

Normalizes a bridge response to plain data; a failed envelope or a non-array gives `[]`.

protected failSoftRead(mixed $response, string $endpoint) : array<string|int, mixed>

NOTE: it does not log on purpose. ApiBridge::call(), which sees both the endpoint and the caller, has already written the API_FAILSOFT source=bridge line; a second copy would turn one failure into three lines in auth.log.

Parameters
$response : mixed
$endpoint : string

only for call readability; the log takes the endpoint from the bridge

Return values
array<string|int, mixed>

getApiCallSource()

Branch marker for writes ({@see ApiBridge::PARAM_SOURCE}), read by the shared repository `SaveTrait`.

protected getApiCallSource() : string
Return values
string

sessionKey()

Returns a stable cart key independent of `Session::getId()`.

private sessionKey() : string

Login calls regenerateId() (SessionStorage::saveAuthentication()), so the raw session id would change at the moment of merging and the cart would be orphaned. The key lives in the same section as the session storage variant but under its own key; the two variants are never used at once (%eshop.cart.storage% is a single switch).

Return values
string
On this page

Search results