File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
androidTest/java/io/snabble/sdk Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
1010### Fixed
1111- Race condition when updating product database and shopping cart prices at the same time
1212- Fixed a bug with BarcodeView not properly fading in when outside bounds
13+ - Reencode user input for zero amount products in backend items
1314
1415## [ 0.13.5]
1516
Original file line number Diff line number Diff line change @@ -276,6 +276,10 @@ public void testBackendCart() {
276276 item .setQuantity (4 );
277277 cart .add (item );
278278
279+ item = zeroAmountProduct .cartItem ();
280+ item .setQuantity (4 );
281+ cart .add (item );
282+
279283 ShoppingCart .BackendCart backendCart = cart .toBackendCart ();
280284 Assert .assertEquals (backendCart .items .length , cart .size ());
281285 Assert .assertEquals (backendCart .items [cart .size () - 1 ].amount , 2 );
@@ -298,6 +302,7 @@ public void testBackendCart() {
298302
299303 Assert .assertEquals (backendCart .items [cart .size () - 6 ].amount , 1 );
300304 Assert .assertEquals (backendCart .items [cart .size () - 6 ].units .intValue (), 4 );
305+ Assert .assertEquals (backendCart .items [cart .size () - 6 ].scannedCode , "2523237000042" );
301306 Assert .assertEquals (backendCart .items [cart .size () - 6 ].weightUnit , Unit .PIECE .getId ());
302307 }
303308
Original file line number Diff line number Diff line change 1212import java .util .concurrent .TimeUnit ;
1313
1414import io .snabble .sdk .codes .ScannedCode ;
15+ import io .snabble .sdk .codes .templates .CodeTemplate ;
1516import io .snabble .sdk .utils .GsonHolder ;
1617
1718import static io .snabble .sdk .Unit .PIECE ;
@@ -608,6 +609,21 @@ public BackendCart toBackendCart() {
608609 item .price = scannedCode .getPrice ();
609610 }
610611
612+ // reencode user input from scanned code with 0 amount
613+ if (cartItem .getUnit () == Unit .PIECE && scannedCode .getEmbeddedData () == 0 ) {
614+ CodeTemplate codeTemplate = project .getCodeTemplate (scannedCode .getTemplateName ());
615+
616+ if (codeTemplate != null ) {
617+ ScannedCode newCode = codeTemplate .code (scannedCode .getLookupCode ())
618+ .embed (cartItem .getEffectiveQuantity ())
619+ .buildCode ();
620+
621+ if (newCode != null ) {
622+ item .scannedCode = newCode .getCode ();
623+ }
624+ }
625+ }
626+
611627 items .add (item );
612628 }
613629
You can’t perform that action at this time.
0 commit comments