Indexing
...
Entities
Custom Entity Types
Entity Discovery
2min
to sync any entities first we have to discover them in order to discover entities for a new entity type we must inject an entitydiscoveryprovider into the entitydiscoveryorchestratorservice e g vendor/module/etc/di xml \<type name="klevu\indexing\service\entitydiscoveryorchestratorservice"> \<arguments> \<argument name="discoveryproviders" xsi\ type="array"> \<item name="custom types" xsi\ type="object">vendor\module\service\provider\customtypeentitydiscoveryprovider\</item> \</argument> \</arguments> \</type> that customtypeentitydiscoveryprovider will be a virtual type of klevu\indexing\service\provider\entitydiscoveryprovider e g vendor/module/etc/di xml \<virtualtype name="vendor\module\service\provider\customtypeentitydiscoveryprovider" type="klevu\indexing\service\provider\entitydiscoveryprovider"> \<arguments> \<argument name="entitytype" xsi\ type="string">custom type\</argument> \<argument name="entityproviders" xsi\ type="array"> \<item name="custom type" xsi\ type="object">vendor\module\service\provider\customtypeentityprovider\</item> \</argument> \<argument name="isindexabledeterminer" xsi\ type="object">vendor\module\service\determiner\isindexabledeterminer\</argument> \</arguments> \</virtualtype> while custom type can be any string as long as it does not clash with any existing types, we advise you do not begin the string with klevu if we add more types in the future and they will begin klevu which could cause a name clash create the customtypeentityprovider which must implement klevu\indexingapi\service\provider\entityproviderinterface class customtypeentityprovider implements entityproviderinterface { public function get(?storeinterface $store = null, ?array $entityids = \[]) ?\generator { $customentitycollection = $this >getcollection(store $store, entityids $entityids); foreach ($customentitycollection as $customentity) { yield $customentity; } } private function getcollection(?storeinterface $store, ?array $entityids) categorycollection { $customentitycollection = $this >customentitycollectionfactory >create(); if ($store) { $customentitycollection >setstore(store (int)$store >getid()); } if ($entityids) { $customentitycollection >addfieldtofilter( entity default entity id field, \['in' => implode(',', $entityids)], ); } return $customentitycollection; } }