Skip to main content
With the help of this function, customers can call up products via QR code or barcode and add them to the basket. A scanner icon in the search field opens the camera in full-screen mode. If a URL is scanned, a direct redirection takes place. If, on the other hand, a barcode is scanned, the product with the scanned ID is placed directly into the basket.

Modules

The following modules are relevant for the integration of Scan & Order:
  • $wsViews - current URL, destination pages, view URLs

Frontend integration

Dependencies

The scanner is based on the open-source library html5-qrcode. The file html5-qrcode.min.js is stored in the scripts/ directory and is only included via lazy load when the scanner is opened.

QR button in the search field

The button is placed directly in front of the search field within the ws-search-box component and opens the scanner. Depending on the end device, it appears in the following locations:
  • in the desktop search bar of the header
    Image
  • in the mobile offcanvas navigation menu
    Image

The integration into the header is done via the file components/layout/header.htm:
The button must be placed identically both in the desktop header and in the mobile offcanvas menu. Using the attribute aria-label=%QRCodeBtnTitle%, the shop text snippets are used for accessibility.
The full-screen modal is inserted once in the base layout. The area #wsQRScanner is responsible for displaying the camera preview from HTML5-QR-Code. The integration is done via the file layouts/default.htm:

JavaScript constant

The path to the library is set as a JavaScript variable in the {{ autoescape "js" }} block of the layout file layouts/default.htm.

Scanner logic

The following code block is to be inserted into the file scripts/wsGlobal.js. The flow is as follows:
  1. When the scanner is opened for the first time, html5-qrcode.min.js is loaded.
  2. If the library was already loaded, the scanner is started directly via wsInitQRScan().
  3. html5-qrcode starts the camera and shows the preview in the #wsQRScanner area.
  4. After a successful scan, URL codes redirect directly to the scanned URL — barcodes place the product with the scanned ID directly into the basket.
  5. When the window is closed, the camera is stopped.