Attribute extends Filter implements Indexable_Interface, Storable_Interface, Filterable_Interface, Countable_Interface, Preloadable_Interface Uses Prefilling_Aware, Search_Query_Array_Aware, Taxonomy_Counts_Provider

Responsible for generating taxonomy related data of global attributes.

Interfaces, Classes and Traits

Indexable_Interface
Indexable_Interface provides a single method "generate_index_data".
Storable_Interface
Represents a filter that should attach data to the frontend react data store.
Filterable_Interface
Indicates that a filter is capable of filtering the WP query.
Countable_Interface
Indicates that the filter can provide a list of counts of the available choices.
Preloadable_Interface
Indicates that a filter should preload counts of possible choices on page load.

Table of Contents

$fillable  : array<string|int, mixed>
$timestamps  : bool
$appends  : array<string|int, mixed>
$casts  : array<string|int, mixed>
Automatically cast attributes in specific ways.\
$childColumn  : string
Indicates the column that should be used by the HasChildren trait to return the appropriate model.
$childTypes  : array<string|int, mixed>
Maps a filter_by value to the appropriate model.
$primaryKey  : string
$table  : string
__construct()  : void
Create a new instance of the model.
create()  : self
Create the filter.
delete()  : bool
Delete child filters if found.
find_posts()  : mixed
generate_index_data()  : array<string|int, mixed>
Generate data for the indexer.
get_all_choices_counts()  : mixed
get_attribute_orderby_args()  : mixed
get_attributes_mode()  : string
Get the attributes mode selected.
get_choices_counts()  : mixed
get_groups()  : Collection
Get a list of the groups to which the filter belongs to.
get_json_store_data()  : mixed
Get the json data to attach to the frontend react data store.
get_option()  : mixed
Get the value of a specific option if it exists.
get_options()  : array<string|int, mixed>
Get the filter's options.
get_search_query()  : mixed
get_specific_attribute()  : string
Get the specific attribute assigned to the filter.
get_specific_terms()  : array<string|int, mixed>
Get the specific terms for the taxonomy filter.
getGroupsAttribute()  : array<string|int, mixed>
Lazy load the list of groups to which the filter has been added to.
getGroupsNamesAttribute()  : array<string|int, mixed>
Lazy load the list of groups to which the filter has been added to.
getHiddenAttribute()  : bool
Determine if this filter is hidden in the admin panel.
getInputNameAttribute()  : string
Retrieve the human readable name of the selected input type for the filter.
getSearchQueryAttribute()  : mixed
Get the search query parameters assigned to the filter.
getSourceNameAttribute()  : string
Retrieve the human readable name of the selected source for the filter.
has_parent()  : bool
Determine if the filter has a parent filter.
include_variations()  : mixed
incrementSlug()  : string
Increment slug
maybe_regenerate_child_filters()  : void
Regenerate the child filters for attributes filters.
setSearchQueryAttribute()  : Filter
Attach search parameters criteria to the filter.
setSlugAttribute()  : void
Automatically set the slug attribute by counting for existing ones.
update()  : bool
Update child filters types when updating the parent filter.
update_groups()  : Filter
Add the filter to the new groups and remove the filter from all other groups.
getChildModel()  : mixed
should_restrict()  : bool
Checks if results should be restricted or merged.
taxonomy_filter_should_restrict()  : bool
Determine if filtering should be restricted to match all filters when one or more filter is enabled and is a checkbox.

Properties

$fillable

public array<string|int, mixed> $fillable = ['name', 'slug', 'filter_by', 'priority', 'options', 'parent_filter']

$timestamps

public bool $timestamps = \false

$appends

protected array<string|int, mixed> $appends = ['source_name', 'input_name', 'search_query', 'hidden']

$casts

Automatically cast attributes in specific ways.\

protected array<string|int, mixed> $casts = ['options' => 'array']

$childColumn

Indicates the column that should be used by the HasChildren trait to return the appropriate model.

protected string $childColumn = 'filter_by'

$childTypes

Maps a filter_by value to the appropriate model.

protected array<string|int, mixed> $childTypes = ['categories' => \Barn2\Plugin\WC_Filters\Model\Filters\Taxonomy::class, 'tags' => \Barn2\Plugin\WC_Filters\Model\Filters\Taxonomy::class, 'attributes' => \Barn2\Plugin\WC_Filters\Model\Filters\Attribute::class, 'colors' => \Barn2\Plugin\WC_Filters\Model\Filters\Color::class, 'price' => \Barn2\Plugin\WC_Filters\Model\Filters\Price::class, 'ratings' => \Barn2\Plugin\WC_Filters\Model\Filters\Rating::class, 'in_stock' => \Barn2\Plugin\WC_Filters\Model\Filters\Stock::class, 'on_sale' => \Barn2\Plugin\WC_Filters\Model\Filters\Sale::class, 'taxonomy' => \Barn2\Plugin\WC_Filters\Model\Filters\Taxonomy::class, 'sorter' => \Barn2\Plugin\WC_Filters\Model\Filters\Sorter::class, 'cf' => \Barn2\Plugin\WC_Filters\Model\Filters\Custom_Field::class, 'search' => \Barn2\Plugin\WC_Filters\Model\Filters\Search::class]

$primaryKey

protected string $primaryKey = 'id'

$table

protected string $table = \Barn2\Plugin\WC_Filters\Plugin::META_PREFIX . 'filters'

Methods

__construct()

Create a new instance of the model.

public __construct([array<string|int, mixed> $attributes = [] ]) : void
Parameters
$attributes : array<string|int, mixed> = []
Return values
void

create()

Create the filter.

public static create([array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $groups = [] ]) : self

If this is an "all attributes" type of filter, create the child filters too.

The $groups parameter is only used for attribute fields when generating child filters.

Parameters
$attributes : array<string|int, mixed> = []
$groups : array<string|int, mixed> = []

list of groups to which the filter should be added to.

Return values
self

delete()

Delete child filters if found.

public delete() : bool
Return values
bool

generate_index_data()

Generate data for the indexer.

public generate_index_data(array<string|int, mixed> $defaults, string $post_id) : array<string|int, mixed>
Parameters
$defaults : array<string|int, mixed>

default index values

$post_id : string

the ID of the post to index

Tags
inheritdoc
Return values
array<string|int, mixed>

get_all_choices_counts()

public get_all_choices_counts([array<string|int, mixed> $post_ids = [] ]) : mixed
Parameters
$post_ids : array<string|int, mixed> = []
Tags
inheritdoc
Return values
mixed

get_attribute_orderby_args()

public get_attribute_orderby_args(mixed $taxonomy) : mixed
Parameters
$taxonomy : mixed
Return values
mixed

get_attributes_mode()

Get the attributes mode selected.

public get_attributes_mode() : string
Return values
string

Either "all" or "specific".

get_choices_counts()

public get_choices_counts(array<string|int, mixed> $post_ids[, mixed $filters = false ][, mixed $prefilling = false ]) : mixed
Parameters
$post_ids : array<string|int, mixed>
$filters : mixed = false
$prefilling : mixed = false
Tags
inheritdoc
Return values
mixed

get_groups()

Get a list of the groups to which the filter belongs to.

public get_groups() : Collection

This method is required because when using Eloquent in WordPress, we cannot reliably build a json relationship.

Return values
Collection

get_json_store_data()

Get the json data to attach to the frontend react data store.

public get_json_store_data() : mixed
Tags
inheritdoc
Return values
mixed

get_option()

Get the value of a specific option if it exists.

public get_option(string $key) : mixed

If not, it returns false.

Parameters
$key : string
Return values
mixed

false when not found

get_options()

Get the filter's options.

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

get_specific_attribute()

Get the specific attribute assigned to the filter.

public get_specific_attribute() : string
Return values
string

get_specific_terms()

Get the specific terms for the taxonomy filter.

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

getGroupsAttribute()

Lazy load the list of groups to which the filter has been added to.

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

getGroupsNamesAttribute()

Lazy load the list of groups to which the filter has been added to.

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

Return an array of ID=>name.

Return values
array<string|int, mixed>

getHiddenAttribute()

Determine if this filter is hidden in the admin panel.

public getHiddenAttribute() : bool

Hidden filters are generated when an "all attributes" type of filter is created.

Return values
bool

getInputNameAttribute()

Retrieve the human readable name of the selected input type for the filter.

public getInputNameAttribute() : string
Return values
string

getSearchQueryAttribute()

Get the search query parameters assigned to the filter.

public getSearchQueryAttribute() : mixed
Return values
mixed

getSourceNameAttribute()

Retrieve the human readable name of the selected source for the filter.

public getSourceNameAttribute() : string
Return values
string

has_parent()

Determine if the filter has a parent filter.

public has_parent() : bool
Return values
bool

include_variations()

public include_variations() : mixed
Return values
mixed

incrementSlug()

Increment slug

public incrementSlug(string $slug) : string
Parameters
$slug : string
Return values
string

maybe_regenerate_child_filters()

Regenerate the child filters for attributes filters.

public static maybe_regenerate_child_filters(Filter $filter) : void
Parameters
$filter : Filter

the filter to regenerate.

Return values
void

setSearchQueryAttribute()

Attach search parameters criteria to the filter.

public setSearchQueryAttribute(mixed $value) : Filter

These are the instructions that will be used via the Filterable_Interface method.

Parameters
$value : mixed
Return values
Filter

setSlugAttribute()

Automatically set the slug attribute by counting for existing ones.

public setSlugAttribute(string $value) : void
Parameters
$value : string
Return values
void

update()

Update child filters types when updating the parent filter.

public update([array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $options = [] ]) : bool
Parameters
$attributes : array<string|int, mixed> = []
$options : array<string|int, mixed> = []
Return values
bool

update_groups()

Add the filter to the new groups and remove the filter from all other groups.

public update_groups(array<string|int, mixed> $selected_groups) : Filter

This method is best used when pre-serving the position of the filter into a group is needed.

Parameters
$selected_groups : array<string|int, mixed>

list of IDs of groups to which the filter should be added to.

Return values
Filter

getChildModel()

protected getChildModel(array<string|int, mixed> $attributes) : mixed
Parameters
$attributes : array<string|int, mixed>
Return values
mixed

should_restrict()

Checks if results should be restricted or merged.

private should_restrict(bool $prefilling[, array<string|int, mixed> $other_filters = [] ]) : bool
Parameters
$prefilling : bool
$other_filters : array<string|int, mixed> = []
Return values
bool

taxonomy_filter_should_restrict()

Determine if filtering should be restricted to match all filters when one or more filter is enabled and is a checkbox.

private taxonomy_filter_should_restrict(mixed $prefilling[, array<string|int, mixed> $other_filters = [] ]) : bool
Parameters
$prefilling : mixed
$other_filters : array<string|int, mixed> = []
Return values
bool

Search results