Hi,
Yesterday I had to find quick solution for using UPC barcodes in POS frontend.
What i did first was to install the chricar_product_gtin module to be able to assing UPC barcodes to products. Bu then I needed to be able to scan them and recognize them in POS frontend. I am not really a developer and the first thing I could figure out watching at the code of devices.js
was to add after if (codeNumbers.length === 13) {
on line:485 the code:
else if (codeNumbers.length === 12) {
if (self.check_ean(codeNumbers.join(''))) {
self.on_ean(codeNumbers.join(''));
codeNumbers = [];
}}
and then change the line:316 to if(code.length !== 13 && code.length !== 12)
So basically it allows 12 number barcodes to be read and if after the 12-th digit it validates it continues as 12-digit (UPC) barcode if not than continues as usual.
It works great but there is one trap: if by chance the first 12 digits of EAN13 barcode make valid UPC code it doesn't work. Actually it happened that in our store we have quite a few products with EAN13 barcode which the first 12 digits by chance construct a valid UPC code.
Is there an easy way to go around this?
I see that devices.js
looks at the time interval between the keys to recognize when we have a barcode reader. I was thinking that if we can check for a longer interval after the 12-th digit like this we'll know that it is a UPC barcode and not a part of EAN13 code. But I couldn't figure it out how to do that.
Any ideas?