Skip to content

Commit d4ea21b

Browse files
committed
reencode user input for zero amount products in backend items
1 parent 5d12a28 commit d4ea21b

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

core/src/androidTest/java/io/snabble/sdk/ShoppingCartTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

core/src/main/java/io/snabble/sdk/ShoppingCart.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.concurrent.TimeUnit;
1313

1414
import io.snabble.sdk.codes.ScannedCode;
15+
import io.snabble.sdk.codes.templates.CodeTemplate;
1516
import io.snabble.sdk.utils.GsonHolder;
1617

1718
import 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

0 commit comments

Comments
 (0)