Start typing to see suggestions. Use arrow keys to navigate, Enter to select.

Cart

Cart class for managing shopping cart functionality in the Fountain plugin.

Information

Property Value
Namespace NymarkType\Fountain
Source /classes/Cart.php

__construct()

Initializes a new Cart instance.

addProduct()

Adds a product to the cart or updates an existing one.

$cart->addProduct( $uuid, $uri, $licenses, $addons );

Parameters

Name Type Description
$uuid string The UUID of the font page.
$uri string|null The URI of the font page.
$licenses array<string> List of license IDs to add.
$addons array<string> List of addon IDs to add.
Returns:
void

Throws:

  • InvalidArgumentException — If the product data is invalid.

removeProduct()

Removes a product from the cart.

$cart->removeProduct( $uuid );

Parameters

Name Type Description
$uuid string The UUID of the font page to remove.
Returns:
void

removeLicense()

Removes a specific license from a product in the cart.

$cart->removeLicense( $uuid, $license );

Parameters

Name Type Description
$uuid string The UUID of the font page.
$license string The license ID to remove.
Returns:
void

removeAddon()

Removes a specific addon from a product in the cart.

$cart->removeAddon( $uuid, $addon );

Parameters

Name Type Description
$uuid string The UUID of the font page.
$addon string The addon ID to remove.
Returns:
void

getProducts()

Retrieves all products in the cart with their licenses and addons as a Kirby Collection of objects.

$cart->getProducts();
Returns:
Kirby\Toolkit\Collection — Obj>

getNumItems()

Gets the number of items in the cart. Returns null if the cart is empty.

$cart->getNumItems();
Returns:
?int

getProductLicenses()

Returns an array of license IDs for the specified product.

$cart->getProductLicenses( $uuid );

Parameters

Name Type Description
$uuid string UUID of the font page.
Returns:
array

hasProduct()

Checks if a product is in the cart.

$cart->hasProduct( $uuid );

Parameters

Name Type Description
$uuid string The UUID of the font page.
Returns:
bool — True if the product is in the cart, false otherwise.

countries()

Returns an associative array of supported countries (code => name).

$cart->countries();
Returns:
array — string>

hasLicense()

Checks if product already has the specified license(s).

$cart->hasLicense( $uuid, $licenses );

Parameters

Name Type Description
$uuid string UUID of the font page.
$licenses array<string>|string License ID(s) to check.
Returns:
bool

hasSiblingLicense()

Checks if license has a sibling in the cart. Returns the sibling license ID or false.

$cart->hasSiblingLicense( $uuid, $license );

Parameters

Name Type Description
$uuid string UUID of the font page.
$license string License ID to check for siblings.
Returns:
string|false

hasAddon()

Checks if product already has the specified addon(s).

$cart->hasAddon( $uuid, $addons );

Parameters

Name Type Description
$uuid string UUID of the font page.
$addons array<string>|string Addon ID(s) to check.
Returns:
bool

hasOverlappingFonts()

Checks if the cart contains an individual font that is also included in a bundle in the cart.

Returns:
bool

updateProduct()

Update product in the cart. Merges new licenses and addons with existing ones. For entity license type, automatically removes sibling licenses.

$cart->updateProduct( $uuid, $uri, $licenses, $addons );

Parameters

Name Type Description
$uuid string UUID of the font page.
$uri string|null URI of the font page.
$licenses array<string>|null License IDs to update.
$addons array<string>|null Addon IDs to update.
Returns:
void

clearEmptyLicenses()

Removes all items from the cart that have no licenses. Returns array of removed items.

$cart->clearEmptyLicenses();
Returns:
array — array<string, mixed>>

clearCart()

Empties the entire cart and removes cart data from session.

$cart->clearCart();
Returns:
void

getLicensee()

Gets the current licensee. Returns false if not set.

$cart->getLicensee();
Returns:
string|false

setLicensee()

Sets the licensee. Throws Exception if licensee is not a string.

$cart->setLicensee( $licensee );

Parameters

Name Type Description
$licensee string Licensee name.
Returns:
bool

Throws:

  • Exception

getJson()

Get JSON representation of the cart. Debug mode returns pretty print.

Returns:
string

getCartData()

Get cart data as array (for JSON responses).

Returns:
array — mixed>

getCartItems()

Get cart items.

Returns:
array — array<int, array<string, mixed>>>

getPaddleCartData()

Returns cart data formatted for Paddle, including licensee and items array.

$cart->getPaddleCartData();
Returns:
array — mixed>

getTitle()

Gets a comma-separated string of all font titles in the cart, with option to truncate.

$cart->getTitle();

Parameters

Name Type Description
$len int Truncate string after length
Returns:
string

getSubtotal()

Calculates the subtotal of the cart based on the current license type, including all products, licenses, and addons.

$cart->getSubtotal();
Returns:
float