SessionCart extends Component uses Container
Shopping cart session wrapper
Table of Contents
Properties
| $components | |
| $helpers | |
| $models | |
| $callbacks | |
| $cart_name |
Methods
| __construct() | Initializes the session cart |
| addItem() | Adds an item to the cart |
| checkQueue() | Returns the first item from the queue without removing it |
| clear() | Clears the cart entirely |
| dequeue() | Removes and returns the first item from the queue |
| emptyCart() | Empties the cart by removing all items from it |
| enqueue() | Adds an item to the queue |
| get() | Returns the cart |
| getData() | Returns a specified field from the cart |
| getItem() | Returns an item in the cart at the given index |
| isEmptyCart() | Returns whether or not the cart is empty |
| isEmptyQueue() | Returns whether or not the queue is empty |
| prequeueItem() | Allows an item to be modified before it is added to the cart |
| removeItem() | Remove an item from the cart |
| removeItems() | Removes a set of items from the cart |
| setCallback() | Sets a callback to be invoked when the given $method is called. |
| setData() | Sets a specified field into the cart with the given value |
| updateItem() | Update an item in the cart |
| getFromContainer() | Fetch an item from the container |
| set() | Set the cart |
Properties
$components
protected
mixed
$components
$helpers
protected
mixed
$helpers
$models
protected
mixed
$models
$callbacks
private
array<string|int, mixed>
$callbacks
= []
An array of callbacks in key/value pairs where each key is the name of the method to invoke the callback on
$cart_name
private
string
$cart_name
The name of the cart to use in the session
Methods
__construct()
Initializes the session cart
public
__construct(int $cart_name, mixed $session) : mixed
Parameters
- $cart_name : int
-
The name of the cart to use in the session
- $session : mixed
addItem()
Adds an item to the cart
public
addItem(mixed $item) : int
Parameters
- $item : mixed
-
The item to add to the cart
Return values
int —The index the item was added to
checkQueue()
Returns the first item from the queue without removing it
public
checkQueue([int $index = 0 ]) : mixed
Parameters
- $index : int = 0
-
The index to peek at
Return values
mixed —An item from the queue, null if no items exist
clear()
Clears the cart entirely
public
clear() : mixed
dequeue()
Removes and returns the first item from the queue
public
dequeue([int $index = 0 ]) : mixed
Parameters
- $index : int = 0
-
The index to dequeue
Return values
mixed —An item from the queue, null if no items exist
emptyCart()
Empties the cart by removing all items from it
public
emptyCart() : mixed
enqueue()
Adds an item to the queue
public
enqueue(mixed $item) : int
Parameters
- $item : mixed
-
An item to add to the queue
Return values
int —The index of the queued item
get()
Returns the cart
public
get() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of cart info including 'items' and any thing else set for the cart
getData()
Returns a specified field from the cart
public
getData(string $field) : mixed
Parameters
- $field : string
-
The field name to fetch
Return values
mixed —The value stored in the cart at $field
getItem()
Returns an item in the cart at the given index
public
getItem(int $index) : mixed
Parameters
- $index : int
-
The index of the item to return
Return values
mixed —The item or null otherwise
isEmptyCart()
Returns whether or not the cart is empty
public
isEmptyCart() : bool
Return values
bool —true if the cart is empty, false otherwise
isEmptyQueue()
Returns whether or not the queue is empty
public
isEmptyQueue() : bool
Return values
bool —true if the queue is empty, false otherwise
prequeueItem()
Allows an item to be modified before it is added to the cart
public
prequeueItem(mixed $item) : mixed
Parameters
- $item : mixed
-
An item to add to the queue
Return values
mixed —Update $item content based on any triggered events
removeItem()
Remove an item from the cart
public
removeItem(int $index) : mixed
Parameters
- $index : int
-
The index of the item to remove from the cart
Return values
mixed —The item removed or null otherwise
removeItems()
Removes a set of items from the cart
public
removeItems(array<string|int, mixed> $indexes) : mixed
Parameters
- $indexes : array<string|int, mixed>
-
A list of indexes matching the cart item indexes for items to remove
setCallback()
Sets a callback to be invoked when the given $method is called.
public
setCallback(string $action, mixed $callback) : mixed
Parameters
- $action : string
-
The action to invoke the callback on (supported actions: addItem, updateItem, removeItem)
- $callback : mixed
setData()
Sets a specified field into the cart with the given value
public
setData(string $field, mixed $value) : mixed
Parameters
- $field : string
-
The field key to set to the session
- $value : mixed
-
The value to save to the cart for the field
updateItem()
Update an item in the cart
public
updateItem(int $index, mixed $item) : mixed
Parameters
- $index : int
-
The index to update
- $item : mixed
-
The item to update at the given index
getFromContainer()
Fetch an item from the container
protected
getFromContainer(string $service) : mixed
Parameters
- $service : string
-
The name of the service from the container to fetch
Return values
mixed —The service if found, otherwise null
set()
Set the cart
private
set(mixed $cart) : mixed
Parameters
- $cart : mixed