Global integration in all templates
In most cases, the search input field (ws-search-box) is integrated in the header of the shop so that the search can be reached from every page.
For the search to work on all pages, certain components and scripts must be included in all templates on which the search input field is displayed. These ensure communication with the search backend and the processing of the search queries.
If the components and scripts should not be included directly in every template, an include area can be created in the FastInclude file (incl_fast_includes.htm) and then referenced in the required templates.
The required components and scripts are described in the following.
WEBSALE JavaScript library
The WEBSALE JavaScript library is required for the integration. It provides all relevant JavaScript modules for the search module as well as other standard shop functions. Depending on requirements, two variants of the library can be included:ws-system-<version identifier>.js- WEBSALE JavaScript modules including the jQuery library.ws-core-<version identifier>.js- WEBSALE JavaScript modules without jQuery. In this case, jQuery must be included separately.
The WEBSALE JavaScript library is only needed once per template. If it is already included in the templates for other shop functions, no further integration is required.
JavaScript bundle
WEBSALE provides a JavaScript bundle with the namews-search-component-<version identifier>.js via the WEBSALE JavaScript library. This bundle is also managed via the WEBSALE PageSpeed tool and is required for the integration and functionality of the search component.
You can include the bundle directly in your templates, like all other JavaScript components provided by WEBSALE, by configuring it via the PageSpeed tool.
If you would like to individualize or adjust the bundle, the file is available for download at the following URL:
Communication component
The communication component is required everywhere the search input field (ws-search-box) is used, but only once per page. It ensures that search queries are processed correctly and transmitted to the backend.
Search input field with optional suggest function
The search input field is included via the<ws-search-box> component. This component represents the frontend input field and can optionally be supplemented with a suggest function.
Additionally, a button for submitting the search query can be integrated via the <ws-search-button> component.
Search event dispatcher & forwarding of search queries
The following script is required to correctly process search queries, provide search results globally in the shop, and forward new search queries to the search result page. It should be included in the<head> of the template.
- Processing the search results (
wsResultDispatcher.subscribe)- Monitors the JSON response of the search module and outputs the received data in the console.
- Creates a list of product numbers and prepares them for an AJAX request to load the product boxes.
- When search results are available,
ws_AJAXloadTemplatePOST()is executed to reload the product boxes.
- AJAX methods for the product box request
- Provides empty functions for the AJAX events
start,success,error, andfailure. - These can be overridden or extended with your own functions as needed.
- Provides empty functions for the AJAX events
- Event listener for new search queries (
wsPerformSearchevent)- Ensures that search queries are forwarded to the search result page.
- As soon as a new search query is started, the URL is adjusted accordingly and the user is forwarded to the result page.
- Extracts search parameters from the URL (
DOMContentLoadedevent)- Loads the current search parameters from the URL when the page is loaded.
- Prepares the parameters for further functions or filter mechanisms.
Integration on the search result page (ws_search.htm)
The default template for displaying the search result page is ws_search.htm.
Using the ws-search-result component
The<ws-search-result> component delivers the product list based on the entered search term, the selected filters, and sort options.
Template placeholder for the product box
To avoid height shifts when loading the product boxes, a<template> can be specified inside ws-search-result. This is displayed as soon as the product box is loaded.
To define the template for the placeholders, result-placeholder must be specified at the slot:
Template for the WEBSALE product box (incl_productbox.htm)
To reload the product box, an additional template must be created and stored in the shop’s template directory (default: translation template directory).
If the name of the template differs from incl_productbox.htm, the associated JavaScript script (see section Search event dispatcher & forwarding of search queries) must be adjusted accordingly.
~WS-Fast_Include(Incl-ProductBoxCategory)~: This is the include area that loads the complete product box with all shop functions.
Incl-ProductBoxCategory usually comes from the file incl_fast_includes.htm, but can be named differently depending on the shop. Make sure to enter the correct include name. Inside the product box, the class wsProductBox-XX (replace XX with the product number) should be present so that these products, if already present, are not reloaded during sorting or filtering.Filtering the search results
Before filters are available in the frontend, the product data fields that can be used for filtering must be defined in the configuration of the search module. This configuration defines which filter types (e.g. checkboxes, sliders) can be used for specific fields. Example for the integration of the filter components:Sorting the search results
The sorting is controlled via the<ws-sort-box> component:
