VuFind API Documentation

Cart
in package

Cart Class

The data model object representing a user's book cart.

Tags
category

VuFind

author

Tuan Nguyen tuan@yorku.ca

license

http://opensource.org/licenses/gpl-2.0.php GNU General Public License

link

Wiki

Table of Contents

CART_COOKIE  = 'vufind_cart'
CART_COOKIE_DELIM  = "\t"
CART_COOKIE_SOURCES  = 'vufind_cart_src'
$active  : bool
Is the cart currently activated?
$cookieManager  : CookieManager
Cookie manager
$items  : array<string|int, mixed>
Cart contents.
$maxSize  : int
Maximum number of items allowed in cart.
$recordLoader  : Loader
Record loader
$showTogglesInSearch  : bool
Is cart configured to toggles in search results?
__construct()  : mixed
Constructor
addItem()  : array<string|int, mixed>
Add an item to the cart.
addItems()  : array<string|int, mixed>
Add an array of items to the cart.
contains()  : bool
Does the cart contain the specified item?
emptyCart()  : void
Empty the cart.
getCookieDomain()  : string
Get cookie domain context (null if unset).
getCookiePath()  : string
Get cookie path ('/' if unset).
getCookieSameSite()  : string
Get cookie SameSite attribute.
getItems()  : array<string|int, mixed>
Return the contents of the cart.
getMaxSize()  : int
Get cart size.
getRecordDetails()  : array<string|int, mixed>
Process parameters and return the cart content.
isActive()  : bool
Check whether cart is enabled.
isActiveInSearch()  : bool
Process parameters and return the cart content.
isEmpty()  : bool
Check whether the cart is empty.
isFull()  : bool
Check whether the cart is full.
removeItems()  : void
Remove an item from the cart.
init()  : void
Initialize the cart model.
save()  : void
Save the state of the cart. This implementation uses cookie so the cart contents can be manipulated on the client side as well.

Constants

public mixed CART_COOKIE = 'vufind_cart'
public mixed CART_COOKIE_DELIM = "\t"
public mixed CART_COOKIE_SOURCES = 'vufind_cart_src'

Properties

$active

Is the cart currently activated?

protected bool $active

$items

Cart contents.

protected array<string|int, mixed> $items

$maxSize

Maximum number of items allowed in cart.

protected int $maxSize

$recordLoader

Record loader

protected Loader $recordLoader

$showTogglesInSearch

Is cart configured to toggles in search results?

protected bool $showTogglesInSearch

Methods

__construct()

Constructor

public __construct(Loader $loader, CookieManager $cookieManager[, int $maxSize = 100 ][, bool $active = true ][, bool $togglesInSearch = true ]) : mixed
Parameters
$loader : Loader

Object for loading records

$cookieManager : CookieManager

Cookie manager

$maxSize : int = 100

Maximum size of cart contents

$active : bool = true

Is cart enabled?

$togglesInSearch : bool = true

Is cart configured to toggles in search results?

Return values
mixed

addItem()

Add an item to the cart.

public addItem(string $item) : array<string|int, mixed>
Parameters
$item : string

ID of item to remove

Return values
array<string|int, mixed>

Associative array with two keys: success (bool) and notAdded (array of IDs that were unable to be added to the cart)

addItems()

Add an array of items to the cart.

public addItems(array<string|int, mixed> $items) : array<string|int, mixed>
Parameters
$items : array<string|int, mixed>

IDs of items to add

Return values
array<string|int, mixed>

Associative array with two keys: success (bool) and notAdded (array of IDs that were unable to be added to the cart)

contains()

Does the cart contain the specified item?

public contains(string $item) : bool
Parameters
$item : string

ID of item to check

Return values
bool

emptyCart()

Empty the cart.

public emptyCart() : void
Return values
void

getCookieDomain()

Get cookie domain context (null if unset).

public getCookieDomain() : string
Return values
string

getCookiePath()

Get cookie path ('/' if unset).

public getCookiePath() : string
Return values
string

getCookieSameSite()

Get cookie SameSite attribute.

public getCookieSameSite() : string
Return values
string

getItems()

Return the contents of the cart.

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

array of items in the cart

getMaxSize()

Get cart size.

public getMaxSize() : int
Return values
int

The maximum cart size

getRecordDetails()

Process parameters and return the cart content.

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

$records The cart content

isActive()

Check whether cart is enabled.

public isActive() : bool
Return values
bool

isActiveInSearch()

Process parameters and return the cart content.

public isActiveInSearch() : bool
Return values
bool

isEmpty()

Check whether the cart is empty.

public isEmpty() : bool
Return values
bool

true if empty, false otherwise

isFull()

Check whether the cart is full.

public isFull() : bool
Return values
bool

true if full, false otherwise

removeItems()

Remove an item from the cart.

public removeItems(array<string|int, mixed> $items) : void
Parameters
$items : array<string|int, mixed>

An array of item IDS

Return values
void

init()

Initialize the cart model.

protected init(array<string|int, mixed> $cookies) : void
Parameters
$cookies : array<string|int, mixed>

Current cookie values

Return values
void

save()

Save the state of the cart. This implementation uses cookie so the cart contents can be manipulated on the client side as well.

protected save() : void
Return values
void

Search results