Indexing
...
Entities
Custom Entity Types
Entity Sync
3min
after discovering the entities, we need to sync them with klevu by injecting entityindexerservice services into the entitysyncorchestratorservice we inject a separate service for each action, i e add , delete and update e g vendor/module/etc/di xml \<type name="klevu\indexing\service\entitysyncorchestratorservice"> \<arguments> \<argument name="entityindexerservices" xsi\ type="array"> \<item name="custom type" xsi\ type="array"> \<item name="add" xsi\ type="object">vendor\module\service\entityindexerservice\add\</item> \<item name="delete" xsi\ type="object">vendor\module\service\entityindexerservice\delete\</item> \<item name="update" xsi\ type="object">vendor\module\service\entityindexerservice\update\</item> \</item> \</argument> \</arguments> \</type> now create each of the injected entityindexerservice you can create your own service classes that implement \klevu\indexingapi\service\entityindexerserviceinterface and handle indexing the data with klevu if you choose this route please refer to the klevu php sdk documentation if you wish to use klevu pipelines to index data with klevu please continue following the example below create a virtual type of klevu\indexing\service\entityindexerservice repeat this step for delete and update vendor/module/etc/di xml \<virtualtype name="vendor\module\service\entityindexerservice\add" type="klevu\indexing\service\entityindexerservice"> \<arguments> \<argument name="entityindexingrecordprovider" xsi\ type="object">vendor\module\service\provider\sync\entityindexingrecordprovider\add\</argument> \<argument name="pipelineconfigurationfilepath" xsi\ type="string">vendor module etc/pipeline/add update yml\</argument> \</arguments> \</virtualtype> \<! repeat for delete and update > create a virtualtype of vendor\module\service\provider\sync\entityindexingrecordprovider (which doesn't exist yet) to set the action to be performed repeat this step for delete and update actions vendor/module/etc/di xml \<virtualtype name="vendor\module\service\provider\sync\entityindexingrecordprovider\add" type="vendor\module\service\provider\sync\entityindexingrecordprovider"> \<arguments> \<argument name="action" xsi\ type="string">add\</argument> \</arguments> \</virtualtype> \<! repeat for delete and update > now create the missing vendor\module\service\provider\sync\entityindexingrecordprovider mentioned in the previous step this is a virtual type of klevu\indexing\service\provider\sync\entityindexingrecordprovider pass in the same entityprovider we created during custom entity types entity discover section vendor/module/etc/di xml \<virtualtype name="vendor\module\service\provider\sync\entityindexingrecordprovider" type="klevu\indexing\service\provider\sync\entityindexingrecordprovider"> \<arguments> \<argument name="entityproviders" xsi\ type="array"> \<! already created in entity discovery section > \<item name="custom type" xsi\ type="object">vendor\module\service\provider\customtypeentityprovider\</item> \</argument> \<argument name="indexingrecordcreatorservice" xsi\ type="object">vendor\module\service\entityindexingrecordcreatorservice\</argument> \<argument name="entitytype" xsi\ type="string">custom type\</argument> \</arguments> \</virtualtype> create vendor\module\service\entityindexingrecordcreatorservice which implements klevu\indexingapi\service\entityindexingrecordcreatorserviceinterface php class entityindexingrecordcreatorservice implements entityindexingrecordcreatorserviceinterface { public function execute( int $recordid, actions $action, pageinterface|extensibledatainterface $entity, pageinterface|extensibledatainterface|null $parent = null, ) entityindexingrecordinterface { return $this >entityindexingrecordfactory >create(\[ 'recordid' => $recordid, 'entity' => $entity, 'parent' => $parent, // this is used when indexing configurable variants if the entity has no parent set this to null 'action' => $action, ]); } } final step is to create the pipeline yaml file to process that data before it is sent to klevu vendor module etc/pipeline/add update yml see pipelines