Skip to main content
Entities are the core of the search, they are the ones that will be searched against, and they are the ones that will be displayed in the search results. You can read more about entities in the Concepts -> Entities page.

AbstractEntity

use Nadir\MerchantBuddy\Entities\AbstractEntity;
All entities should extend the AbstractEntity class, which initself implments EntityInterface. AbstactEntity injects the currently selected provider into the entity, which can be accessed via $this->provider.
protected: provider
ProviderInterface
The search provider currently selected in the search settings.
searchable_fields
string[]
default:"[]"
An array of fields that should be searchable, this is used by the provider to index said fields.
display_fields
string[]
default:"[]"
An array of fields that should be displayed, this is used by the provider to return only the needed fields.
get_searchable_fields(): array
string[]
Returns an array of fields that should be searchable, this is used by the provider to index said fields. This method can be overridden to return a different array of fields via filters.
get_display_fields(): array
string[]
Returns an array of fields that should be displayed, this is used by the provider to return only the needed fields. This method can be overridden to return a different array of fields via filters.

EntityInterface

use Nadir\MerchantBuddy\Entities\EntityInterface;
Entities are required to implement EntityInterface, which is done via using AbstactEntity.
get_entity_slug(): string
string
Returns a unique slug for the entity, to avoid dubplicates, this should be whatever slug WordPress will use, like a custom post type or taxonomy or user role.
get_entity_label(): string
string
Returns a plural, human readable, transatable name for the entity.
init_hooks(): void
void
Should be where hooks to create, update, and delete items for this entity are registred. This is called for enabled entities.
search( query: string): array
Item[]
This is relevant if you’re using the default provider, this method will search the entity based on a search query.
get_item_data( object $item ): array
array
Should take an entity object (WC_Order, WC_Customer, WC_Product…) and returns an array of which data to persist, and what data to display in the search results, returns an object of properties and values, the same keys are used in layout, searchable_fields and display_fields.
layout(): array
array
Returns an array that describes which template to use, how to bind its values, and what actions to use. The array has the following shape:

Layout

A layout function must return an array with the following shape:
  [
    "template" => AbstractTemplate::class,
    "bindings" => [
      "template_key" => "binding_key"
    ],
    "actions" => [
      "primary_action" => [
        "label" => "string",
        "url" => "binding_key"
      ],
      "secondary_action" => [
        "label" => "string",
        "url" => "binding_key"
      ]
    ]
  ]
template: string
string
The class name of the template to use. Read more about templates here.
bindings: array
array
An array that describes what value to bind to which placeholder in the template.Bindings can be icons, images, single text, or several text values that gets merged.
actions: array
array
An array that describes what actions to use, for now, actions are limited to full redirect, future versions will include internal redirects (inside the search bar).

Batchable

use Nadir\MerchantBuddy\Entities\Contracts\Batchable;
Entities that support batch queries should implement a Batchable contract, which require a single method:
get_items( int $page = 1, int $per_page = 10 ): array
array
Takes current pagination and returns an array of length $per_page and items of get_item_data array shape.