Cache

Cache helper methods.

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

Table of Contents

ACTIVE_CART_DISCOUNT_CACHE_KEY  = 'wdm_active_cart_discount_cache'
DISCOUNTS_CACHE_KEY  = 'wdm_discounts_cache'
VIRTUAL_COUPON_CACHE_KEY  = 'wdm_virtual_coupon_cache'
$active_discounts  : array<string|int, mixed>
The list of discounts that have been successfully applied to the cart and/or order.
$discounted_products  : array<string|int, mixed>
The list of discounted products that have been successfully discounted in the cart and/or order.
$tracked_discounts  : array<string|int, mixed>
Holds the list of products that have been discounted in the cart and/or order.
add_discounted_product()  : self
Add a product to the list of discounted products.
clear_active_discounts()  : self
Clear the list of active discounts that have been successfully applied to the cart and/or order.
clear_discounted_products()  : self
Clear the list of discounted products.
forget_cached_published_discounts()  : void
Forget the cached list of discounts.
get_active_discounts()  : array<string|int, mixed>
Get the list of active discounts that have been successfully applied to the cart and/or order.
get_discounted_products()  : array<string|int, mixed>
Get the list of discounted products.
get_published_discounts()  : array<string|int, Discount>
Retrieve a cached list of discounts that are currently enabled and ordered by priority.
get_tracked_discount_id_by_product()  : int
Retrieve the discount ID that has been successfully applied to a product in the cart and/or order.
get_tracked_discounts()  : array<string|int, mixed>
Get the list of products that have been discounted in the cart and/or order.
has_active_discounts()  : bool
Determine whether the list of active discounts is empty or not.
has_discounted_product()  : bool
Determine whether a product is in the list of discounted products.
has_discounted_products()  : bool
Determine whether the list of discounted products is empty.
is_discount_active()  : bool
Determine whether a discount is active.
mark_discount_as_active()  : self
Mark a discount as active and store it in the list of active discounts.
mark_discount_as_inactive()  : self
Mark a discount as inactive and remove it from the list of active discounts.
track_discount()  : self
Track a discount that has been successfully applied to a product in the cart and/or order.

Constants

ACTIVE_CART_DISCOUNT_CACHE_KEY

public mixed ACTIVE_CART_DISCOUNT_CACHE_KEY = 'wdm_active_cart_discount_cache'

DISCOUNTS_CACHE_KEY

public mixed DISCOUNTS_CACHE_KEY = 'wdm_discounts_cache'

VIRTUAL_COUPON_CACHE_KEY

public mixed VIRTUAL_COUPON_CACHE_KEY = 'wdm_virtual_coupon_cache'

Properties

$active_discounts

The list of discounts that have been successfully applied to the cart and/or order.

protected array<string|int, mixed> $active_discounts = []

$discounted_products

The list of discounted products that have been successfully discounted in the cart and/or order.

protected array<string|int, mixed> $discounted_products = []

$tracked_discounts

Holds the list of products that have been discounted in the cart and/or order.

protected array<string|int, mixed> $tracked_discounts = []

Methods

add_discounted_product()

Add a product to the list of discounted products.

public add_discounted_product(int $product_id) : self
Parameters
$product_id : int

The product ID.

Return values
self

clear_active_discounts()

Clear the list of active discounts that have been successfully applied to the cart and/or order.

public clear_active_discounts() : self
Return values
self

clear_discounted_products()

Clear the list of discounted products.

public clear_discounted_products() : self
Return values
self

forget_cached_published_discounts()

Forget the cached list of discounts.

public static forget_cached_published_discounts() : void
Return values
void

get_active_discounts()

Get the list of active discounts that have been successfully applied to the cart and/or order.

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

The list of active discounts.

get_discounted_products()

Get the list of discounted products.

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

The list of discounted products.

get_published_discounts()

Retrieve a cached list of discounts that are currently enabled and ordered by priority.

public static get_published_discounts() : array<string|int, Discount>
Return values
array<string|int, Discount>

The list of discounts.

get_tracked_discount_id_by_product()

Retrieve the discount ID that has been successfully applied to a product in the cart and/or order.

public get_tracked_discount_id_by_product(int $product_id) : int

This method is used to determine which discount has been applied to a product in the cart and/or order.

Parameters
$product_id : int

The product ID.

Return values
int

The discount ID.

get_tracked_discounts()

Get the list of products that have been discounted in the cart and/or order.

public get_tracked_discounts() : array<string|int, mixed>

This returns an associative array where the keys are the discount IDs and the values are the list of product IDs that have been discounted by that discount.

Return values
array<string|int, mixed>

The list of products that have been discounted.

has_active_discounts()

Determine whether the list of active discounts is empty or not.

public has_active_discounts() : bool
Return values
bool

Whether the list of active discounts is empty.

has_discounted_product()

Determine whether a product is in the list of discounted products.

public has_discounted_product(int $product_id) : bool
Parameters
$product_id : int

The product ID.

Return values
bool

Whether the product is in the list of discounted products.

has_discounted_products()

Determine whether the list of discounted products is empty.

public has_discounted_products() : bool
Return values
bool

Whether the list of discounted products is empty.

is_discount_active()

Determine whether a discount is active.

public is_discount_active(Discount $discount) : bool
Parameters
$discount : Discount

The discount.

Return values
bool

Whether the discount is active.

mark_discount_as_active()

Mark a discount as active and store it in the list of active discounts.

public mark_discount_as_active(Discount $discount) : self

This method does not add the discount to the database. It is used to keep track of which discounts are currently active in the cart and/or order.

Parameters
$discount : Discount
Return values
self

mark_discount_as_inactive()

Mark a discount as inactive and remove it from the list of active discounts.

public mark_discount_as_inactive(Discount $discount) : self

This method does not remove the discount from the database. It is used to keep track of which discounts are currently active in the cart and/or order.

Parameters
$discount : Discount
Return values
self

track_discount()

Track a discount that has been successfully applied to a product in the cart and/or order.

public track_discount(int $discount_id, int $product_id) : self
Parameters
$discount_id : int

The discount ID.

$product_id : int

The product ID.

Return values
self

Search results