CartItem
extends BaseEntity
in package
implements
IdentifiableInterface
uses
IdentifiableTrait
AbstractYes
Line of a persistent cart: set id and quantity, without a price.
Surrogate PK (not a composite (cart, productSet)), following the IdentifiableTrait
convention; uniqueness of the pair is enforced by a unique index in the database.
productSet has no FK constraint (index only): a deleted product silently disappears from
the front end list, the same as it does from the session cart.
Tags
Attributes
- #[MappedSuperclass]
- #[TableAlias]
- $alias: 'cartItem'
Table of Contents
Interfaces
- 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
- $cart : TCart|null
- $id : int|null
- $productSet : TProductSet|null
- $quantity : int
Methods
- __construct() : mixed
- 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.
- getCart() : TCart|null
- getId() : int|null
- getProductSet() : TProductSet|null
- getQuantity() : int
- isPersisted() : bool
- setCart() : $this
- setId() : $this
- setProductSet() : $this
- setQuantity() : $this
- getTraitsRecursive() : array<string, string>
- Walks the trait list recursively and collects nested traits too.
Properties
$cart
protected
TCart|null
$cart
= null
$id
protected
int|null
$id
= null
Attributes
- #[Column]
- $name: 'cart_item_id'
- $type: 'integer'
- $options: ['unsigned' => true]
- #[GeneratedValue]
- #[Id]
$productSet
protected
TProductSet|null
$productSet
= null
$quantity
protected
int
$quantity
= 1
Attributes
- #[Column]
- $name: 'quantity'
- $type: 'integer'
- $options: ['unsigned' => true]
Methods
__construct()
public
__construct([int|null $id = null ][, mixed $cart = null ][, mixed $productSet = null ][, int $quantity = 1 ]) : mixed
Parameters
- $id : int|null = null
- $cart : mixed = null
- $productSet : mixed = null
- $quantity : int = 1
callInitMethods()
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>getCart()
public
getCart() : TCart|null
Return values
TCart|nullgetId()
public
getId() : int|null
Return values
int|nullgetProductSet()
public
getProductSet() : TProductSet|null
Return values
TProductSet|nullgetQuantity()
public
getQuantity() : int
Return values
intisPersisted()
public
isPersisted() : bool
Return values
boolsetCart()
public
setCart(TCart|null $cart) : $this
Parameters
- $cart : TCart|null
Return values
$thissetId()
public
setId(int|null $id) : $this
Parameters
- $id : int|null
Return values
$thissetProductSet()
public
setProductSet(TProductSet|null $productSet) : $this
Parameters
- $productSet : TProductSet|null
Return values
$thissetQuantity()
public
setQuantity(int $quantity) : $this
Parameters
- $quantity : int
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>