Skip to content

Sorting

danneg edited this page Jan 22, 2021 · 7 revisions

In order for the API request to happen, the ApiSortingModelInterface dependency that has to be declared.

If no search/navigation/listing feature is to be used, declare an empty dependency, without sorting options.

The Sorting integration might change throught Shopware6 versions used in your project. This can be adapted in the Integration Layer.

About

This section information is a window into the technical/coding choice for making your system`s sorting options work with the Boxalino API framework.

The ApiSortingModelInterface is used:

  1. in the API RequestTransformer in order to set/validate the sorting rule for the request.
  2. for the Sorting model, that manages the sorting options available on the store frontend
    • it is a data model for the sample sorting template part of the guidelines

In the framework repository is provided the structure which is used:

  1. ApiSorting model
  • it is used as a "model" property on the sorting Boxalino Layout Block.
  • it converts the accessor for bx-sort, which has access to active sort and the sorting options

Integration

  1. Declare the ApiSortingModelInterface preference
  2. Identify the desired frontend sorting options ((the presented are the default Shopware6 sorting fields) (https://github.com/shopware/platform/blob/v6.3.2.0/src/Core/Content/DependencyInjection/product.xml#L195)

Check the propper rtux-integration-shopware tag matching your Shopware6 version as described here https://github.com/boxalino/rtux-integration-shopware/wiki/CHANGELOG#shopware-versions

  1. Identify the Boxalino fields required for as data-source
  2. Add the sorting options as arguments to the model.
  3. Add translation snippets in your theme/integration module.

If you check the sorting layout block from the JSON samples, it will use the ApiSortingModel as a model for the element.

Adding new sorting fields

until Shopware 6.3.2

  1. Follow the Shopware6 documentation on how to declare new sorting fields (depends on your Shopware6 version) (ex: for v6.3.2 https://github.com/boxalino/rtux-integration-shopware/blob/2.3.0/src/Resources/config/services/api/page.xml#L40 )
  2. Declare new fields to the collection by updating the XML (ex: https://github.com/boxalino/rtux-integration-shopware/blob/2.3.0/src/Resources/config/services/api/page.xml#L35)
  3. Add translation snippets for the new sorting option label

starting with Shopware 6.3.3

  1. Add a new sorting option to the declared collection (https://github.com/boxalino/rtux-integration-shopware/blob/2.5.2/src/Resources/config/services.xml#L31)

In the sorting.html.twig template, the sorting element is represented by the API SortingOption data object

  1. Add translation for the new sorting option label