Stock extends Filter implements Indexable_Interface, Filterable_Interface, Countable_Interface, Preloadable_Interface Uses Simple_Finder, Counts_Provider

Represents the "in stock" filter.

Interfaces, Classes and Traits

Indexable_Interface
Indexable_Interface provides a single method "generate_index_data".
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 the filter from the database.
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_choices_counts()  : mixed
get_groups()  : Collection
Get a list of the groups to which the filter belongs to.
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
Return the formatted searched string attached to the 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.
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_groups()  : Filter
Add the filter to the new groups and remove the filter from all other groups.
getChildModel()  : mixed

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 the filter from the database.

public delete() : bool

This has a cascading effect:

  • deletes all data indexed for this filter
  • removes the filter from all groups to which it was added.
Return values
bool —

find_posts()

public find_posts() : mixed
Tags
inheritdoc
Return values
mixed —

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_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_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_search_query()

Return the formatted searched string attached to the filter.

public get_search_query() : mixed
Tags
inheritdoc
Return values
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 —

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_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 —

Search results