Skip to content

Extensibility

WARNING

This Article use many Code-References to GitLab! Please contact the Shopware Sales department to get access to the private repository. Find more information in our Enterprise Contribution Guidelines

To implement the full search experience for a own entity, you have to implement multiple interfaces.

The Search/Suggest Gateway

Here you can create a own SuggestGatewayInterface/SearchGatewayInterface or use the already existing SearchGateway.

The Enterprise Search offers two ways to extend the search / suggest results. You can implement the following Interfaces within your services:

Or use the existing class:

E.g., for your definition it means the following:

html
<service id="YourStuff" class="Swag\EnterpriseSearch\Suggest\SuggestGateway">
  <argument type="service" id="definition.repository"/>
  <argument type="service" id="Swag\EnterpriseSearch\Suggest\SuggestCriteriaBuilder"/>

  <tag name="swag_ses.suggest_gateway" key="yourDefinition"/>
</service>

The following tags and keys are used for registering the services in the search / suggest:

text
swag_ses.suggest_gateway
swag_ses.search_gateway

The tagged services are used in the following files:

The search template

For showing the results in the search overview, you have to extend the search/index.html.twig and then apply the results in your desired styling.

You can take a look for an example here:

Checking your Browser - GitLab

The suggest gateway

For showing the results in the suggest dropdown, you have to extend Storefront/storefront/layout/header/search-suggest.html.twig like the Enterprise Search does:

Checking your Browser - GitLab

Admin Boosting detail

For creating boostings based on your definition, you have to add the name to the following file.

Currently, the values are hardcoded. See here for reference:

Checking your Browser - GitLab

Configuration Initial Value

For a first search, you also need a first pair of configuration entries. Therefore you have to create a migration. An example could look like this:

php
        $salesChannels = $connection->fetchAll('SELECT `id` FROM `sales_channel`');

        foreach ($salesChannels as $salesChannel) {
            $ids = [
                'manufacturer' => Uuid::randomHex(),
                'category' => Uuid::randomHex(),
                'product' => Uuid::randomHex(),
                'salesChannel' => $salesChannel['id'],
            ];

            $defaults = "
                INSERT INTO `gateway_configuration`
                (`id`, `entity_name`, `sales_channel_id`, `max_suggest_count`, `max_search_count`, `created_at`) VALUES
                (UNHEX(:product), 'product', :salesChannel, 10, null, NOW()),
                (UNHEX(:manufacturer), 'product_manufacturer', :salesChannel, 10, 30, NOW()),
                (UNHEX(:category), 'category', :salesChannel, 10, 30, NOW())
            ";

            $connection->executeQuery($defaults, $ids);
        }

This can be found in the Swag\EnterpriseSearch\Migration\Migration1584020367CreateNewGatewayConfiguration file:

Checking your Browser - GitLab

Configuration Entity

For adding a new configuration while creating a SalesChannel, you have to create your own Swag\EnterpriseSearch\Configuration\GatewayConfigurationCreator and override the getEntityNames() with your additional entity.

Autocompletion

For adding auto-completion of your definition, you have to add a CompletionEsDefinitionDecorator to it. See this example:

html
 <service id="swag_completion.manufacturer_es_definition"
          class="Swag\EnterpriseSearch\Completion\CompletionEsDefinitionDecorator"
          decorates="Swag\EnterpriseSearch\Manufacturer\ManufacturerEsDefinition">
      <argument type="service" id="swag_completion.manufacturer_es_definition.inner"/>

      <tag name="swag_ses.completion_definition"/>
 </service>

You can also change the extendEntities() here to apply "multi words auto suggestions".

Additional Filtering

You may want to filter your definition. This can be done by extending the CriteriaBuilder. An example can be found in Swag\EnterpriseSearch\Category\SalesChannelCategorySearchCriteriaBuilder:

Checking your Browser - GitLab