Barcodes and QR-codes in SAP hybris


Barcodes are machine readable symbols that store identifying data about the part or product with which they are associated. Basically, it is a paper-based hyperlink that connects the physical world with the online world. This article explains everything you need to know about the barcode reading and generation in hybris, as well as my thoughts about the integrating it into hybris Backoffice. In e-commerce, barcodes are mainly used for:
  • inventory management
  • ready to pick up e-mails
  • discount coupons ready to use in offline retail
Two last processes are shown at the diagram below. So the barcodes helps user to deliver the some code (order number or coupon number) to the physical store. We’ll focus on these applications of barcodes primarily as specific for the e-commerce. process Barcodes are being used as a form of virtual ticket that you can print from your PC at home or show on your phone screen or in printed form to gain access to some data, bus tickets, train tickets, promotional coupons, to gain access to a venue or be entitled to something valuable as pick up orders in the store.

Integrating barcode reader into Backoffice

The best and recommended way is using barcode scanning devices (from $100). They generally work as a keyboard wedge (between the PC and its normal keyboard) or as a USB deviceIf you have any severe reasons for not following this advice, develop your own desktop or mobile app based on the existing libraries and frameworks and use a mobile phone as a reader. If you have severe reasons not to go this way, you can try the budget solutions explained below. Disclaimer! Remember that there’s no such thing as a free lunch! The following apps are good for the proof-of-concepts and demonstrations, but not for full-scale solution in the core of your business. Even if they work reliably today, nothing is stopping the authors from unpublishing the apps at any time. You will need two apps installed on your android phone, BarCode scanner (Free) and ClipSync (Free). You will need to install a ClipSync server (Freeware). The first app recognizes the barcodes, the second app transmits the code to your PC in the background.  All you need on your PC is to press Ctrl-V. This solution works on Windows only.  Make sure your device’s camera supports auto focus. kart.png Another interesting solution is QuaggaJS. Using this library you can read barcodes using an external webcam connected as USB device.  Take a look at the demo pages to get an idea of what this project is all about (take into mind that non-autofocus webcameras may not work with any barcode scanner because of poor quality of captured images). It is not just a simple scanner, but a scanner equipped with localization mechanisms to find a barcode in real-time. The core parts of QuaggaJS are made up of computer vision algorithms.  There are two modes in which Quagga operates: 1. analyzing static images and 2. using a camera to decode the images from a live-stream. Here is a very interesting article on how the barcode localization works in QuaggaJS. There is another implementation in Javascript (http://eddiela.github.io/JOB/), MIT license (free for commercial use).   It supports reading Code128, Code93, Code39, Standard/Industrial 2 of 5, Interleaved 2 of 5, Codabar and EAN-13 barcodes. For QR codes you can use WebQR (demo / github)

Generating Barcodes

The best and recommended way is using 3rd party Java/Javascript libraries for generating barcodes. For example, ZXing 3.3.0 / BarcodeJ. If you have any reasons not to code at all, you can try the free service Barcodes For Me. It generates a barcode on the fly, at the time of the request, you need to create a proper URL. For example, the URL for the following image is
www.barcodes4.me/barcode/c128a/Rauf%20Aliev%20barcode.png?width=250&height=100&istextdrawn=1
JsBarcode is also a great library. It has a MIT License, so you can use it in the commercial projects as well.  Unlike the previous libraries, this one generates vector (SVG) images.

Hybris OOTB solutions for barcodes

There is a module “mobileservices” in hybris. It provides the functionality of decoding barcodes, “Code2Service” (documentation). The module supports QR and DataMatrix barcodes. For DataMatrix — only encoding. Hybris uses ZXing library for generating/decoding QR codes. However, this version (1.3) is too old: it is released in 2013, four year ago. The current version is 3.3.0. It supports an extended set of barcode formats, bugfixed and stable.  So consider updating the library comes with hybris with a new version. For Datamatrix codes, hybris uses BarcodeJ. However, hybris uses only a small subset of this library capabilities. I found the following comments in hybris that the datamatrix library “fails to decode non-alphanumeric characters” and “The errors produced, varies with the encoding string. The longer the string, the worse results“. So take it into account.

Security issues

Barcode ticket security is a growing issue (we get asked about it all the time) and there aren’t any standards yet for preventing unscrupulous individuals from altering the tickets that are issued. As the value of barcode entitlements go up, more people will take an interest in copying, altering, or re-generating valuable barcodes. Without the security, the ticket cannot be proof. Ideally, barcodes should contain just a number (order number, coupon number etc.), and their validity is checked from a database of known numbers, which reveals all of the extra order/coupon detail, possibly including ID information about the legitimate user of the ticket which might be checked in high value situations. The problem of this approach is that your checking systems must have up-to-date access to the ticket database, ideally near real-time access. Sometimes it is a challenging issue (for example, for event tickets). If your POS system relies on the scanners being connected to the internet, to access a central database to check every barcode, then you may get issues with speed of validating, and therefore the throughput of your entry systems. Additionally, your whole system could become useless from a single point of failure or connection. So if we go this way, the barcode is no more than a representation of the order number and you need to conduct additional security checks before handover. If you use a self-service terminals, the system can be hacked with a set of pre-printed QR-codes with different order numbers. To avoid attacking I recommend using unique salted hashes instead of simple sequential numbering. If you can put all of the details of the purchase into a QR code, then an offline system can scan it, and instantly know what the entitlement is without the need to access a database.  It can work for tickets, for example. However, this approach require Public/Private key cryptography. This approach is good for online ticketing systems. For regular e-commerce it looks like an overkill. Never put the sensitive information into QR code. QR code should contain only a reference where this sensitive information can be retrieved from by the system with the proper permissions. To avoid the replay attack you need to keep a database of issued barcodes and their values. When a barcode is redeemed, the database must invalidate that code. This approach can be implemented via item statuses. It works best if your system is online and synchronous, where codes are atomically applied and cancelled. It is also possible to limit the window during which codes can be re-used in a batch processing based system if the terminals cannot be online, though any use of a code between when it is first redeemed and when that redemption is copied to other systems is a risk. This case is common for coupons issued online and supposed to be redeemed offline. Some codes have strict limitations on the character set and message length. You need to test it well before going live. Finally, you need to have a backup plan for the case when barcode is not readable.

Forms of barcodes

Over the years, different forms of barcodes have been developed to help businesses around the world. These include:
  • 1-D linear barcodes
  • 2-D matrix codes
  • Posted codes
  • Stacked linear barcodes

1-D linear barcodes

  • All the information in the code is organized horizontally in bar and space widths and read left to right by a scanner.
  • The height of the code varies based on the space available on a product and the ability of a barcode reader to read a small or large sized barcode.

Code 128

  • 2017-06-11_12h41_27multi-width, alphanumeric
  • a more recently introduced
  • the most robust 1-D barcode type.
  • The number 128 refers to the ability to hold any character of the ASCII 128 character set (all digits, characters and punctuation marks).
  • Typical usage: Logistics
Code 128: UPC-A
  • 2017-06-11_12h45_01.pngUPC means Unversal Product Code
  • The most common and well-known barcode used in the United States
  • Encodes 12 digits of data
  • The 1st digit is the number system character followed by a 5-digit manufacturer number, a 5-digit product number and a final check digit.
  • UPC-A is primarily used in retail.  
Code 128: EAN-13
  • 2017-06-11_12h47_10European counterpart of the UPC-A symbol.
  • Encodes an extra digit of data to make a total of 13.
  • The first two digits identify a country and the check digit is the last number of the second group of six digits.
Code 128: UPC-E
  • 2017-06-11_12h48_32Used in U.S.
  • Condensed variation of a UPC-A barcode (eliminating ‘extra’ zeros from the digital data).
  • Generally used on very small packaging where space is limited
Code 128: EAN-8
  • 2017-06-11_12h51_08.pngEAN equivalent of UPC-E (in the sense that it provides a short barcode).
  • Set in two groups of four numbers, it is composed of two flag digits, five data digits and one check digit.
  • Primarily used on small packaging where space is limited.

Code 39 (aka “3 of 9 code”)

  • 2017-06-11_12h53_41Variable-length barcode
  • Self-checking so a check digit normally isn’t necessary, but is recommended.
  • Ability to encode up to 43 numbers, letters and other characters.
  • Widely used, especially in non-retail environments
Code 39 Extended version
  • 2017-06-11_12h57_05Combination of two standard Code 39 characters to encode every one of the 128 ASCII characters.
  • Allows for special characters, such as lowercase letters.
  • The more special characters that are used, the longer the barcode will become.
  • Most barcode readers will not automatically read Extended Code 39 without custom configuration.

Code 93

  • 2017-06-11_12h58_28.pngDesigned to encode data more compactly and with higher data redundancy than with older multi-length barcode types such as Code 39.

Codabar

  • 2017-06-11_13h00_04Discrete, self-checking barcode that allows encoding of up to 16 different characters, plus an additional four special start and stop characters, which include A, B, C and D.

Interleaved 2 of 5

  • 2017-06-11_13h02_20Encodes any even number of numeric characters.
  • Encodes data in the width of both the bars and spaces (resulted in higher density encoding)

MSI/Plessey (aka Modified Plessey)

  • 2017-06-11_13h03_56Used primarily to mark supermarket shelves for inventory control.
  • MSI is a continuous, non-self-checking barcode.

2-D matrix codes

  • Data is encoded as black and white ‘cells’ (small squares) arranged in either a square or rectangular pattern.
  • Ability to encode larger amounts of data
  • The matrix code improves readability and resistance to poor printing
  • Include redundant data so even if one or more cells are damaged, the code is still readable.

Data Matrix

  • 2017-06-11_13h08_03Allows encoding of large amounts of data (up to 2,335 alphanumeric or 3,116 numerical characters)
  • Uses an error correction system to read codes that are as much as 40% damaged.
  • They are made up of black and white cells in a square or rectangular pattern, a finder pattern and a timing pattern.

MaxiCode

  • 2017-06-11_13h09_36.pngFixed-size code which holds up to 93 data characters.
  • Composed of a central bulls-eye locator and offset rows of hexagonal elements.
  • Created by United Parcel Service (UPS) to allow quick, automated scanning of packages on high-speed conveyor lines (Barcode readers can read a MaxiCode on a carton traveling at up to 550 feet/minute or 168 meters/minute).

QR Code

  • 2017-06-11_13h10_50Contain square blocks of black cells on a white background with finder patterns in the top left, top right, and bottom left corners.
  • QR was developed with the intention of being used for tracking parts during vehicle assembly.

Aztec

  • 2017-06-11_13h11_25Named after the resemblance of the central finder pattern to an Aztec pyramid, the code is built on a square grid with a bulls-eye pattern at its center for locating the code.
  • Data is encoded in concentric square rings around the bulls-eye pattern.
  • Aztec codes have the potential to use less space than other matrix barcodes because they do not require a surrounding blank ‘quiet zone’.

Postal codes

  • Instead of encoding data in the black bar and white space widths, these primarily use the height of the bars.
  • Used primarily for numbers

PostNET

  • The POSTNET (Postal Numeric Encoding Technique) barcode is used by the U.S. Postal Service to automatically sort mail.
  • Encodes data in the height of the bars.
2017-06-11_13h05_10.png

Intelligent Mail Barcode (IMB)

  • Used to sort and track letters and flats.
  • Сarries sender’s information.
2017-06-11_13h06_36.png

Stacked linear barcodes

PDF 417

  • Ability to store up to 1,800 printable ASCII characters or 1,100 binary characters per symbol.
  • It is also possible to break large amounts of data into several PDF417 codes which are linked together.
  • In theory, there is no limit to the amount of data that can be stored in a group of PDF417 symbols.
pdf417

© Rauf Aliev, June 2017

2 Responses

  1. Cristian Caprar

    Cristian Caprar

    Reply

    12 June 2017 at 03:36

    Very good overview of the possibilities.

  2. rbespalov

    rbespalov

    Reply

    27 June 2017 at 03:49

    – How do you spend your weekends?
    – I’m building Proof of Concepts for hybris ?
    Regarding the problem with proofing code in offline mode and disallowing the same code twice. It’s hard for me to imagine a case when you don’t have at least LAN available through Wifi. Having local connection the solution that comes to mind is that local server once in while syncs the codes with the external internet server.
    When a user comes by and presents a barcode to the offline store (train, event), then it is verified against the local server only. If it’s already marked as used – sorry, someone else just used it in the same area.
    That doesn’t cover the case when someone is using the same discount code simultaneously in New York and San Francisco but for most of the cases it should be enough.

Leave a Reply