<ws-search-result> component is responsible for displaying the results of a search or filtering in the storefront. It processes the response of the search module and outputs a reference for each product or category found.
Component
Results are grouped per index – for each index (for exampleproduct, category), a separate <ws-search-result> instance is used, which can be placed freely in the layout.
source: Specifies the source index whose results this instance displays. If nosourceis set, the component behaves as before. Possible values:productcategorytab: Only relevant within ws-search-result-tabs. Bundles severalws-search-resultinstances in a shared tab. Withouttab, thesourceforms the tab.content
use-ajax: Specifies whether an Ajax call is used to reload the WEBSALE product boxes.true/yes: An Ajax call is used.- If not set, the web components render the product boxes.
wrapper-class: Sets the CSS class for the wrapper container. Relevant when rendering directly via the component (that is, whenuse-ajax="no").item-class: Sets the CSS class for the individual result items. Relevant when rendering directly via the component (that is, whenuse-ajax="no").
Placeholder template
To avoid height shifts while the boxes load, a<template> with the slot result-placeholder can be specified within <ws-search-result>. It is displayed as a placeholder for each result until the box is fully loaded.
HTML output
Products (source="product"): The component generates a container with the ID prefix wsProductWebComponent- and the attribute data-product-id for each product found. Via this ID the WEBSALE product box can be reloaded via AJAX.
source="category"): For the category results, the ID prefix wsCategoryWebComponent- and the attribute data-category-id are used analogously. The ID is used in the storefront by the AJAX script to reload the WEBSALE category box.
Total container
The<ws-search-result> component also takes care of rendering total containers. A total container displays information about the total number of search results and the current pagination.
Important: The CSS class total-container must be contained in the class attribute so that the component detects and renders the container.
Example
ws-search-result:
source: The index whose total is to be displayed. Possible values areproduct,category, andcontent.data-template: A string template that is used to render thetextContent. Contains placeholders that are replaced with the actual values:{%result.total%}: Total number of search results.{%result.from%}: Pagination: from which result the display starts (for example1→ displays starting from the first result).{%result.to%}: Pagination: up to which result is displayed (for example24→ displays up to the 24th result).
product, category, content) and the cross-index overall total is to be displayed, use ws-search-info without a source attribute.
From
ws-search-component-1.9.1.js onwards, the ws-search-info component handles the hit display – including the cross-index overall total, which previously required a script in the template. The approach described here can still be used, but should no longer be used in new projects.This solution is only necessary if more than one index is used.
Debugging and output in the console
To check the display of the results against the technical response, you can use the following script. It prints the results to the browser console:To make the fields under
_source available, you need to contact WEBSALE Support. They enable the fields in the backend configuration.CSS & styling
The<ws-search-result> component itself does not generate any specific CSS classes. Styling is defined entirely via the <template> tag. Within this template you can use any CSS statements to customize the display of the search results.