Home > Software design >  Shopware 6 add entity extension fields to admin search
Shopware 6 add entity extension fields to admin search

Time:06-28

I wonder how to make some fields of an entity extension searchable in the administration through the "/api/search/my-entity" api-endpoint. By default they are not considered during search as it looks like.

CodePudding user response:

As far as the API is concerned, search functionality should automatically be generated following your custom entity definitions.

When it comes to facilitate Admin search for your entity, you need to add some code to the administration component as described in the docs: https://developer.shopware.com/docs/guides/plugins/plugins/administration/search-custom-data (even though it looks not fully up-to-date w.r.t to the current Shopware versions).

CodePudding user response:

I found the answer by debugging the search-endpoint:
The association-Field of the EntityExtension needs to have a SearchRanking-flag:

...->addFlags(new SearchRanking(SearchRanking::ASSOCIATION_SEARCH_RANKING))

Then you can add SearchRanking-flags in the EntityExtensionDefinition as you like, e.g.:

(new StringField('test', 'test'))->addFlags(new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),

After that the fields are searchable via the search-endpoint :)

  • Related