Cart_Handler implements Service, Registerable, Conditional
This class handles caching for the product tables.
Tags
Interfaces, Classes and Traits
- Service
- Registerable
- Conditional
Table of Contents
- add_to_cart() : mixed
- add_to_cart_multi() : array<string|int, mixed>
- Add multiple products to the cart in a single step.
- get_multi_cart_data() : array<string|int, mixed>
- Get the posted multi cart data as an array, with the correct integer product IDs.
- is_required() : mixed
- process_multi_cart() : mixed
- register() : mixed
- fix_cart_data_product_ids() : array<string|int, mixed>
- Posted cart_data uses indexes of the form 'p1234' where '1234' is the product ID.
Methods
add_to_cart()
public
static add_to_cart(mixed $product_id[, mixed $quantity = 1 ], mixed $variation_id[, mixed $variations = [] ]) : mixed
Parameters
- $product_id : mixed
- $quantity : mixed = 1
- $variation_id : mixed
- $variations : mixed = []
Return values
mixed —add_to_cart_multi()
Add multiple products to the cart in a single step.
public
static add_to_cart_multi(array<string|int, mixed> $products) : array<string|int, mixed>
Parameters
- $products : array<string|int, mixed>
-
- An array of products (including quantities and variation data) to add to the cart
Return values
array<string|int, mixed> —An array of product IDs => quantity added
get_multi_cart_data()
Get the posted multi cart data as an array, with the correct integer product IDs.
public
static get_multi_cart_data() : array<string|int, mixed>
Return values
array<string|int, mixed> —The multi cart data (product IDs => product data)
is_required()
public
is_required() : mixed
Return values
mixed —process_multi_cart()
public
process_multi_cart() : mixed
Return values
mixed —register()
public
register() : mixed
Return values
mixed —fix_cart_data_product_ids()
Posted cart_data uses indexes of the form 'p1234' where '1234' is the product ID.
private
static fix_cart_data_product_ids(array<string|int, mixed> $cart_data) : array<string|int, mixed>
This is because of a limitation of the JS serializeObject function. We run this function to remove the 'p' prefix from each index in the array.
Parameters
- $cart_data : array<string|int, mixed>
-
The cart data to be sanitized
Return values
array<string|int, mixed> —The same array with keys replaced with the corresponding product ID