Sorting, ordering and paging

The Navigation and Search requests support sorting (or ordering) and paging (also known as pagination).

Sorting

The available sort options in the response come from the applied Builder Template. To implement different ways of sorting of items, use properties.sortoptions to display different sort options:

<navigation xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <facets>
    <!-- omitted for brevity -->
  </facets>
  <items>
    <!-- omitted for brevity -->
	</items>
	<properties>
    <!-- omitted for brevity -->
    <sortfields>
      <sortfield>
        <title>Recommended</title>
        <displaytitle>Recommended</displaytitle>
        <order>ASC</order>
        <isselected>true</isselected>
        <url>?tn_cid=100022&tn_sort=Recommended</url>
      </sortfield>
      <sortfield>
        <title>New</title>
        <displaytitle>New</displaytitle>
        <order>ASC</order>
        <isselected>false</isselected>
        <url>?tn_cid=100022&tn_sort=New</url>
      </sortfield>
      <sortfield>
        <title>Price asc</title>
        <displaytitle>Price low - high</displaytitle>
        <order>ASC</order>
        <isselected>false</isselected>
        <url>?tn_cid=100022&tn_sort=Price+asc</url>
      </sortfield>
    </sortfields>
    <!-- omitted for brevity -->
  </properties>
</navigation>
<select name="Sort">
  <option value="Recommended">Aanbevolen</option>
  <option value="New">New</option>
  <option value="Price asc">Prijs low - high</option>
</select>

To sort or not to sort, that is the question

To get the most out of Tweakwise, by default the tn_sort parameter should not be applied. Because, if the tn_sort parameter is applied to requests to Tweakwise, Merchandising Builder and Merchandising Pins will not be applied.

This also means that, if a user has selected a different sorting option and wants to return to the primary/default sort option (usually Recommended), make sure the sorting is not applied anymore. And consequently the tn_sort parameter is not added to the requests to Tweakwise anymore.

This is visible in the demoshop, where the sorting is correctly reset:

Paging

By default, a paging priciple is applied to our dataset. The defaults for paging are configurable in the app. Using the configured values, combined with the search result, we calculate some of the properties necessary for implementing paging.

These properties can be used to implement paging in your platform:

  • nrofitems: total number of items in the searchresult.
  • pagesize: number of items per page, corresponds to the tn_ps parameter.
  • nrofpages: total number of pages, based on pagesize and nrofitems.
  • currentpage: currently selected page, corresponds to the tn_p parameter.