Cart
extends BaseEntity
in package
implements
OwnerAwareInterface, IdentifiableInterface
uses
IdentifiableTrait, UserAssociationOwnerTrait
Persistent shopping cart stored in the database, the alternative to the default session storage (chosen per deployment by `%eshop.cart.storage%`, see {@see \App\UI\Front\Eshop\Models\Mappers\CartMapperFactory}).
The cart holds no price, rate or discount, only identifiers and customer-entered texts; prices are always computed by the server at checkout.
IMPORTANT: sessionKey (unique) is the cart's own stable key, never Session::getId().
Login calls regenerateId(), so a raw session id would change exactly when carts are
merged and the cart would be orphaned.
checkoutData is the JSON form of the array the session storage keeps (customer,
delivery, isCompany, isVatPayer, useDelivery, tariffId, branchId,
paymentMethodId, note). It is deliberately not split into columns: columns cannot tell
"key never set" from "set to empty", which mergeCheckout() and the login merge
(a non-empty value wins) rely on.
items and vouchers are owned collections replaced in full on every save.
IMPORTANT: CartManager::saveSnapshot() always builds fresh entities and never reuses a
managed instance, because reusing one in a replaced collection silently deletes its row.
Tags
Attributes
- #[MappedSuperclass]
- #[TableAlias]
- $alias: 'cart'
Table of Contents
Interfaces
- OwnerAwareInterface
- Entity that knows who created it (the owner is the author or sender of the record); the named entry point to the generic base of the conditional RBAC role `owner`.
- IdentifiableInterface
- Entity with a simple integer primary key. Most entities have one (often via {@see \App\Core\Traits\Shared\Models\Entities\IdentifiableTrait}); texts and links with a composite key do not, which is why `getId()` is not on {@see \App\Core\Base\BaseEntity}. Code that needs the id of a generic entity asks for this interface (parameter type, template bound, `instanceof`).
Properties
- $checkoutData : string|null
- $currency : TCurrency|null
- $id : int|null
- $insertDatetime : DateTime|null
- $items : Collection<int, TItem>
- $language : TLanguage|null
- $sessionKey : string
- $updateDatetime : DateTime|null
- $user : TUser|null
- $vouchers : Collection<int, TVoucher>
Methods
- __construct() : mixed
- addItem() : $this
- addVoucher() : $this
- callInitMethods() : void
- Calls `init{TraitName}()` for every used trait that defines such a method.
- getAllTraits() : array<string, string>
- Returns all traits the class uses, including those used by parent classes and nested traits.
- getCheckoutData() : string|null
- getCurrency() : TCurrency|null
- getId() : int|null
- getInsertDatetime() : DateTime|null
- getItems() : Collection<int, TItem>
- getLanguage() : TLanguage|null
- getOwnerUserId() : int|null
- getSessionKey() : string
- getUpdateDatetime() : DateTime|null
- getUser() : TUser|null
- getVouchers() : Collection<int, TVoucher>
- isPersisted() : bool
- setCheckoutData() : $this
- setCurrency() : $this
- setId() : $this
- setInsertDatetime() : $this
- setItems() : $this
- setLanguage() : $this
- setSessionKey() : $this
- setUpdateDatetime() : $this
- setUser() : $this
- setVouchers() : $this
- getTraitsRecursive() : array<string, string>
- Walks the trait list recursively and collects nested traits too.
Properties
$checkoutData
protected
string|null
$checkoutData
= null
Attributes
- #[Column]
- $name: 'checkout_data'
- $type: 'text'
- $nullable: true
$currency
protected
TCurrency|null
$currency
= null
$id
protected
int|null
$id
= null
Attributes
- #[Column]
- $name: 'cart_id'
- $type: 'integer'
- $options: ['unsigned' => true]
- #[GeneratedValue]
- #[Id]
$insertDatetime
protected
DateTime|null
$insertDatetime
= null
Attributes
- #[Column]
- $name: 'insert_datetime'
- $type: 'datetime'
$items
protected
Collection<int, TItem>
$items
= new ArrayCollection()
$language
protected
TLanguage|null
$language
= null
$sessionKey
protected
string
$sessionKey
= ''
Attributes
- #[Column]
- $name: 'session_key'
- $type: 'string'
- $length: 64
- #[FieldAccess]
- $read: Audience::Internal
- $insert: Audience::All
- $update: Audience::All
$updateDatetime
protected
DateTime|null
$updateDatetime
= null
Attributes
- #[Column]
- $name: 'update_datetime'
- $type: 'datetime'
- $nullable: true
$user
protected
TUser|null
$user
= null
$vouchers
protected
Collection<int, TVoucher>
$vouchers
= new ArrayCollection()
Methods
__construct()
public
__construct([int|null $id = null ][, string $sessionKey = '' ][, mixed $user = null ][, mixed $currency = null ][, mixed $language = null ][, string|null $checkoutData = null ][, DateTime|null $insertDatetime = null ][, DateTime|null $updateDatetime = null ][, Collection $items = new ArrayCollection() ][, Collection $vouchers = new ArrayCollection() ]) : mixed
Parameters
- $id : int|null = null
- $sessionKey : string = ''
- $user : mixed = null
- $currency : mixed = null
- $language : mixed = null
- $checkoutData : string|null = null
- $insertDatetime : DateTime|null = null
- $updateDatetime : DateTime|null = null
- $items : Collection = new ArrayCollection()
- $vouchers : Collection = new ArrayCollection()
addItem()
public
addItem(TItem $item) : $this
Parameters
- $item : TItem
Return values
$thisaddVoucher()
public
addVoucher(TVoucher $voucher) : $this
Parameters
- $voucher : TVoucher
Return values
$thiscallInitMethods()
Calls `init{TraitName}()` for every used trait that defines such a method.
public
callInitMethods() : void
getAllTraits()
Returns all traits the class uses, including those used by parent classes and nested traits.
public
getAllTraits() : array<string, string>
Return values
array<string, string>getCheckoutData()
public
getCheckoutData() : string|null
Return values
string|nullgetCurrency()
public
getCurrency() : TCurrency|null
Return values
TCurrency|nullgetId()
public
getId() : int|null
Return values
int|nullgetInsertDatetime()
public
getInsertDatetime() : DateTime|null
Return values
DateTime|nullgetItems()
public
getItems() : Collection<int, TItem>
Return values
Collection<int, TItem>getLanguage()
public
getLanguage() : TLanguage|null
Return values
TLanguage|nullgetOwnerUserId()
public
getOwnerUserId() : int|null
Return values
int|nullgetSessionKey()
public
getSessionKey() : string
Return values
stringgetUpdateDatetime()
public
getUpdateDatetime() : DateTime|null
Return values
DateTime|nullgetUser()
public
getUser() : TUser|null
Return values
TUser|nullgetVouchers()
public
getVouchers() : Collection<int, TVoucher>
Return values
Collection<int, TVoucher>isPersisted()
public
isPersisted() : bool
Return values
boolsetCheckoutData()
public
setCheckoutData(string|null $checkoutData) : $this
Parameters
- $checkoutData : string|null
Return values
$thissetCurrency()
public
setCurrency(TCurrency|null $currency) : $this
Parameters
- $currency : TCurrency|null
Return values
$thissetId()
public
setId(int|null $id) : $this
Parameters
- $id : int|null
Return values
$thissetInsertDatetime()
public
setInsertDatetime(DateTime|null $insertDatetime) : $this
Parameters
- $insertDatetime : DateTime|null
Return values
$thissetItems()
public
setItems(Collection<int, TItem>|array<int, TItem> $items) : $this
Parameters
- $items : Collection<int, TItem>|array<int, TItem>
Return values
$thissetLanguage()
public
setLanguage(TLanguage|null $language) : $this
Parameters
- $language : TLanguage|null
Return values
$thissetSessionKey()
public
setSessionKey(string $sessionKey) : $this
Parameters
- $sessionKey : string
Return values
$thissetUpdateDatetime()
public
setUpdateDatetime(DateTime|null $updateDatetime) : $this
Parameters
- $updateDatetime : DateTime|null
Return values
$thissetUser()
public
setUser(TUser|null $user) : $this
Parameters
- $user : TUser|null
Return values
$thissetVouchers()
public
setVouchers(Collection<int, TVoucher>|array<int, TVoucher> $vouchers) : $this
Parameters
- $vouchers : Collection<int, TVoucher>|array<int, TVoucher>
Return values
$thisgetTraitsRecursive()
Walks the trait list recursively and collects nested traits too.
private
static getTraitsRecursive(array<string, string> $traits) : array<string, string>
Parameters
- $traits : array<string, string>