Skip to content

Commit 89495b7

Browse files
committed
fix price display & transmit barcode encoded price to backend
1 parent 11e76d5 commit 89495b7

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ private PayloadCart getPayloadCart() {
240240
item.units = quantity;
241241
}
242242

243+
if (item.price == null && item.units != null && scannedCode.hasPrice()) {
244+
item.price = item.units * scannedCode.getPrice();
245+
}
246+
243247
payloadCart.items[i] = item;
244248
}
245249

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,11 @@ public int getTotalPrice() {
422422
} else if (e.price != null) {
423423
sum += e.price;
424424
} else if (e.amount != null) {
425-
sum += product.getPrice() * e.amount;
425+
int productPrice = product.getDiscountedPrice();
426+
if (e.scannedCode.hasPrice()) {
427+
productPrice = e.scannedCode.getPrice();
428+
}
429+
sum += productPrice * e.amount;
426430
} else {
427431
sum += product.getPriceForQuantity(e.quantity, e.scannedCode, project.getRoundingMode());
428432
}

core/src/main/java/io/snabble/sdk/encodedcodes/EncodedCodesGenerator.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,19 @@ private void addProducts(ShoppingCart shoppingCart, boolean ageRestricted) {
101101
Collections.sort(productInfos, new Comparator<ProductInfo>() {
102102
@Override
103103
public int compare(ProductInfo p1, ProductInfo p2) {
104-
if (p1.product.getDiscountedPrice() < p2.product.getDiscountedPrice()) {
104+
int price1 = p1.product.getDiscountedPrice();
105+
if (p1.scannedCode.hasPrice()) {
106+
price1 = p1.scannedCode.getPrice();
107+
}
108+
109+
int price2 = p2.product.getDiscountedPrice();
110+
if (p2.scannedCode.hasPrice()) {
111+
price2 = p2.scannedCode.getPrice();
112+
}
113+
114+
if (price1 < price2) {
105115
return -1;
106-
} else if (p1.product.getDiscountedPrice() > p2.product.getDiscountedPrice()) {
116+
} else if (price1 > price2) {
107117
return 1;
108118
}
109119

ui/src/main/java/io/snabble/sdk/ui/cart/ShoppingCartView.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,17 @@ public void bindTo(final int position) {
477477

478478
String price = priceFormatter.format(product, true, scannedCode);
479479

480+
int productPrice = product.getDiscountedPrice();
481+
if (scannedCode.hasPrice()) {
482+
productPrice = scannedCode.getPrice();
483+
}
484+
480485
if (embeddedPrice != null) {
481486
priceTextView.setText(" " + priceFormatter.format(embeddedPrice));
482487
} else if (embeddedAmount != null) {
483488
priceTextView.setText(String.format(" * %s = %s",
484-
priceFormatter.format(product.getPrice()),
485-
priceFormatter.format(product.getPrice() * embeddedAmount)));
489+
priceFormatter.format(productPrice),
490+
priceFormatter.format(productPrice * embeddedAmount)));
486491
} else if (embeddedWeight != null) {
487492
String priceSum = priceFormatter.format(product.getPriceForQuantity(embeddedWeight, scannedCode, roundingMode));
488493
priceTextView.setText(String.format(" * %s = %s", price, priceSum));
@@ -545,7 +550,7 @@ public void bindTo(final int position) {
545550
}
546551

547552
// special case if price is zero we assume its a picking product
548-
if (product.getDiscountedPrice() == 0) {
553+
if (productPrice == 0) {
549554
controlsDefault.setVisibility(View.GONE);
550555
controlsUserWeighed.setVisibility(View.GONE);
551556
}

ui/src/main/java/io/snabble/sdk/ui/scanner/ProductConfirmationDialog.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ public void show(Product newProduct, ScannedCode scannedCode) {
117117
unit = scannedCode.getEmbeddedUnit();
118118
}
119119

120+
int productPrice = product.getDiscountedPrice();
121+
if (scannedCode.hasPrice()) {
122+
productPrice = scannedCode.getPrice();
123+
}
124+
120125
if (scannedCode.hasEmbeddedData()) {
121126
if (Unit.hasDimension(unit)) {
122127
quantityAnnotation.setText(getNonNullEncodingUnit(product, scannedCode).getDisplayValue());
@@ -157,7 +162,7 @@ public void show(Product newProduct, ScannedCode scannedCode) {
157162

158163
// special case if price is zero we assume its a picking product and hide the
159164
// controls to adjust the quantity
160-
if (product.getDiscountedPrice() == 0) {
165+
if (productPrice == 0) {
161166
plus.setVisibility(View.GONE);
162167
minus.setVisibility(View.GONE);
163168
quantity.setText("1");
@@ -318,14 +323,19 @@ private void updatePrice() {
318323
encodingDisplayValue = encodingUnit.getDisplayValue();
319324
}
320325

326+
int productPrice = product.getDiscountedPrice();
327+
if (scannedCode.hasPrice()) {
328+
productPrice = scannedCode.getPrice();
329+
}
330+
321331
if (q > 0 && (Unit.hasDimension(encodingUnit) || product.getType() == Product.Type.UserWeighed)) {
322332
price.setText(String.format("%s %s * %s = %s", String.valueOf(q), encodingDisplayValue, singlePrice, priceText));
323333
} else if (q > 1) {
324334
if (encodingUnit == Unit.PIECE) {
325335
price.setText(String.format("%s * %s = %s",
326336
String.valueOf(q),
327-
priceFormatter.format(product.getPrice()),
328-
priceFormatter.format(product.getPrice() * q)));
337+
priceFormatter.format(productPrice),
338+
priceFormatter.format(productPrice * q)));
329339
} else {
330340
price.setText(String.format("%s * %s = %s", String.valueOf(q), singlePrice, priceText));
331341
}

0 commit comments

Comments
 (0)