Formula
Model for handling price formula data.
Tags
Table of Contents
- $custom_functions : array<string|int, mixed>
- A list of custom functions.
- $data : array<string|int, mixed>
- The formula data.
- $exclude_product_price : bool
- Whether to exclude the product price from the formula.
- $option_id : int
- The option ID.
- $settings : array<string|int, mixed>
- The option settings.
- __construct() : mixed
- Constructor.
- check_validity() : bool
- Determines whether the current data is sufficient to evaluate the formula.
- exclude_product_price() : bool
- Whether the product product price should be excluded because of the formula.
- get_custom_variables() : array<string|int, mixed>
- Gets the price formula variables for the field.
- get_expression() : string
- Gets the expression for the executor.
- get_formula() : string
- Gets the price formula for the field.
- get_valid() : string
- Gets the price formula variables for the field.
- get_variables() : array<string|int, mixed>
- Gets the price formula variables for the field.
- save() : mixed
- Saves the formula data to the database.
- set_custom_variables() : void
- Sets the price formula variables for the field.
- set_expression() : void
- Sets the expression for the executor.
- set_formula() : void
- Sets the price formula for the field.
- set_valid() : void
- Sets the valid status of the formula.
- set_variables() : void
- Sets the price formula variables for the field.
- update_variable_id() : mixed
- Updates a variable id in the formula.
- update_variable_name() : mixed
- Updates a variable name in the formula.
Properties
$custom_functions
A list of custom functions.
private
array<string|int, mixed>
$custom_functions
The custom functions are provided as an associative array where the key is the function name and the value is the function definition.
Tags
$data
The formula data.
private
array<string|int, mixed>
$data
Tags
$exclude_product_price
Whether to exclude the product price from the formula.
private
bool
$exclude_product_price
Tags
$option_id
The option ID.
private
int
$option_id
Tags
$settings
The option settings.
private
array<string|int, mixed>
$settings
Tags
Methods
__construct()
Constructor.
public
__construct(Option $option) : mixed
Parameters
- $option : Option
Tags
Return values
mixed —check_validity()
Determines whether the current data is sufficient to evaluate the formula.
public
check_validity() : bool
Tags
Return values
bool —exclude_product_price()
Whether the product product price should be excluded because of the formula.
public
exclude_product_price() : bool
Return values
bool —get_custom_variables()
Gets the price formula variables for the field.
public
get_custom_variables() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_expression()
Gets the expression for the executor.
public
get_expression([string|null $custom_variable_name = null ]) : string
The expression is stored in the formula configuration. Nevertheless, there might be situations where the expression cannot be updated because the update only occurs on the client side when a formula is edited. This means that the expression stored in the database might be outdated and not reflect the current formula. To avoid this, we manually regenerate the expression here by: * converting the expression to lower case; * iteratively replacing custom variables with their formulas; * removing the square brackets around each variable name.
Additionally, we can pass a custom variable name to get the expression for that variable instead of the expression for the main formula.
Parameters
- $custom_variable_name : string|null = null
-
Optionally, the name of the custom variable to get the expression for.
Tags
Return values
string —get_formula()
Gets the price formula for the field.
public
get_formula() : string
Tags
Return values
string —get_valid()
Gets the price formula variables for the field.
public
get_valid() : string
Tags
Return values
string —get_variables()
Gets the price formula variables for the field.
public
get_variables() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —save()
Saves the formula data to the database.
public
save() : mixed
Tags
Return values
mixed —set_custom_variables()
Sets the price formula variables for the field.
public
set_custom_variables(array<string|int, mixed> $variables) : void
Parameters
- $variables : array<string|int, mixed>
Tags
Return values
void —set_expression()
Sets the expression for the executor.
public
set_expression(string $expression) : void
Parameters
- $expression : string
Tags
Return values
void —set_formula()
Sets the price formula for the field.
public
set_formula(string $formula) : void
Parameters
- $formula : string
Tags
Return values
void —set_valid()
Sets the valid status of the formula.
public
set_valid(bool $valid) : void
Parameters
- $valid : bool
Tags
Return values
void —set_variables()
Sets the price formula variables for the field.
public
set_variables(array<string|int, mixed> $variables) : void
Parameters
- $variables : array<string|int, mixed>
Tags
Return values
void —update_variable_id()
Updates a variable id in the formula.
public
update_variable_id(int $new_id, int $old_id) : mixed
Parameters
- $new_id : int
- $old_id : int
Tags
Return values
mixed —update_variable_name()
Updates a variable name in the formula.
public
update_variable_name(int $option_id, string $name) : mixed
Parameters
- $option_id : int
- $name : string