File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
core/src/main/java/io/snabble/sdk Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
33
44## [ 0.30.1]
55
6+ ### Added
7+ - Support for UPC-A codes in EAN13 or EAN14 codes
8+
69### Changed
710- Prioritize online payment methods over offline methods if available
811- Route to entering payment method if not available
Original file line number Diff line number Diff line change @@ -1276,15 +1276,39 @@ public Product findByCode(ScannedCode scannedCode) {
12761276 return null ;
12771277 }
12781278
1279+ Product product = findByCode (scannedCode .getLookupCode (), scannedCode .getTemplateName ());
1280+
1281+ // try again for upc codes
1282+ if (product == null ) {
1283+ String upcCode = extractUpcA (scannedCode .getLookupCode ());
1284+ if (upcCode != null ) {
1285+ return findByCode (upcCode , scannedCode .getTemplateName ());
1286+ }
1287+ }
1288+
1289+ return product ;
1290+ }
1291+
1292+ private Product findByCode (String lookupCode , String templateName ) {
12791293 Cursor cursor = productQuery ("JOIN scannableCodes s ON s.sku = p.sku " +
12801294 "WHERE s.code = ? AND s.template = ? LIMIT 1" , new String []{
1281- scannedCode . getLookupCode () ,
1282- scannedCode . getTemplateName ()
1295+ lookupCode ,
1296+ templateName
12831297 }, false );
12841298
12851299 return getFirstProductAndClose (cursor );
12861300 }
12871301
1302+ private String extractUpcA (String code ) {
1303+ if (code .length () == 13 && code .startsWith ("0" )) {
1304+ return code .substring (1 );
1305+ } else if (code .length () == 14 && code .startsWith ("00" )) {
1306+ return code .substring (2 );
1307+ } else {
1308+ return null ;
1309+ }
1310+ }
1311+
12881312 private Product [] findBundlesOfProduct (Product product ) {
12891313 Cursor cursor = productQuery ("WHERE p.bundledSku = ?" , new String []{
12901314 product .getSku ()
You can’t perform that action at this time.
0 commit comments