Skip to content

Autocomplete (Server Fallback)

danneg edited this page Jan 22, 2021 · 10 revisions

Please be aware that there have to be designed Layout Blocks in Boxalino Intelligence Admin

Make sure there is a narrative linked to the widget "autocomplete"

JSON samples of both elements are provided with these guidelines and must be imported in your Boxalino Intelligence Admin panel. Make sure to replace the @BoxalinoRealTimeUserExperienceIntegration namespace with your project`s

Boxalino recommends to have a JS integration of the autocomplete. The JSON elements can be imported from there directly. The server fallback strategy described before is only used if/when the JS requests fail.

Steps

1. Declare a service for the autocomplete definition request

https://github.com/boxalino/rtux-integration-shopware/blob/master/src/Resources/config/services/api/autocomplete.xml (widget name, context, etc)

as an integrator, you can either build your own (following the sample) or extend it (it provides generic filters) for each use-case in order to set more filters if desired or other parameters (return fields, etc)

the Autocomplete[Context] will be the one to make the request by using an entity called RequestTransformer [https://github.com/boxalino/rtux-shopware/blob/master/src/Framework/Request/RequestTransformer.php] and adding extra filters per context: https://github.com/boxalino/rtux-shopware/tree/master/src/Framework/Request/ContextAbstract.php#L98

2. Declare a service for the ApiPageLoader

Shopware works with the concept of PageContentLoader, so there is one provided for the framework: https://github.com/boxalino/rtux-shopware/blob/master/src/Framework/Content/Page/ApiPageLoader.php

This content loader is generic and it has to be declared as a service. On it`s declaration, it is configured the ApiContextInterface which is context-specific (autocomplete, navigation, etc). The Autocomplete API Context and has been created&declared at the prior step.

3. Decorate the SearchController and use the ApiPageLoader as a dependency

Decorate the controller service by making use of the Autocomplete ApiPageLoader from step#2

The context ApiPageContentLoader is being used in the controller/cms pages/etc
The ApiPageLoader has access to Autocomplete[Context] request definition and to the ApiCallService The ApiPageLoader makes the call to the Boxalino API https://github.com/boxalino/rtux-shopware/blob/master/src/Framework/Content/Page/ApiPageLoader.php#L70

(more about decorating the SearchController in the Search Context guidelines)

4. Create the SearchController

It will be used in order to rewrite the actual suggest action. https://github.com/boxalino/rtux-integration-shopware/blob/master/src/Storefront/Controller/SearchController.php#L98

5. Adjust the templates

For the autocomplete, you can either use the response as it comes from Boxalino (without loading a collection of products) or define a model on the product list component and load each product as ProductEntity objects (more about the model https://github.com/boxalino/rtux-integration-shopware/blob/master/doc/search/INTEGRATION.md#L104 ) The templates can be found here: https://github.com/boxalino/rtux-integration-shopware/tree/master/src/Resources/views/storefront/narrative/layout/header/suggest