Skip to content

Commit 94ed72b

Browse files
authored
Remove product confirmation dialog (Apps-2411) (#256)
1 parent d8fdde6 commit 94ed72b

22 files changed

+154
-1294
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
55
### Added
66
### Changed
77
### Removed
8+
ui: Remove ProductConfirmationDialog (APPS-2411)
89
### Fixed
910

1011
## [0.80.17]

core/src/main/java/io/snabble/sdk/PriceFormatter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class PriceFormatter(private val project: Project) {
6666
if (referenceUnit == null) {
6767
referenceUnit = Unit.KILOGRAM
6868
}
69-
if (type == Product.Type.UserWeighed || type == Product.Type.PreWeighed) {
69+
if (type == Product.Type.PreWeighed) {
7070
formattedString += " / " + referenceUnit.displayValue
7171
}
7272
return formattedString
@@ -88,4 +88,4 @@ class PriceFormatter(private val project: Project) {
8888
}
8989
return format(product, price)
9090
}
91-
}
91+
}

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,7 @@ public enum Type {
3737
* Scanned codes usually have a different code the code you get from {@link Product#getScannableCodes()}, containing the
3838
* price information.
3939
*/
40-
PreWeighed(1),
41-
42-
/**
43-
* A product that needs to be user weighed. The price from {@link Product#getListPrice()}
44-
* is a base price of 1000g
45-
*/
46-
UserWeighed(2);
40+
PreWeighed(1);
4741

4842
private final int databaseValue;
4943

@@ -419,7 +413,7 @@ public int getPriceForQuantity(int quantity, ScannedCode scannedCode, RoundingMo
419413
* Uses the customer card price as a base instead of the normal price
420414
*/
421415
public int getPriceForQuantity(int quantity, ScannedCode scannedCode, RoundingMode roundingMode, String customerCardId) {
422-
if (type == Product.Type.UserWeighed || type == Product.Type.PreWeighed) {
416+
if (type == Product.Type.PreWeighed) {
423417
String lookupCode = scannedCode != null ? scannedCode.getLookupCode() : null;
424418

425419
Unit referenceUnit = this.referenceUnit;

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ private static class ApiProduct {
2020
String name;
2121
String description;
2222
String subtitle;
23-
boolean weighByCustomer;
2423
String referenceUnit;
2524
String encodingUnit;
2625
String imageUrl;
@@ -111,7 +110,7 @@ public void findBySku(String sku, final OnProductAvailableListener productAvaila
111110
HttpUrl.Builder builder = baseUrl.newBuilder();
112111

113112
Shop shop = Snabble.getInstance().getCheckedInShop();
114-
if(shop != null) {
113+
if (shop != null) {
115114
builder.addQueryParameter("shopID", shop.getId());
116115
}
117116

@@ -150,7 +149,7 @@ public void findByCode(final ScannedCode code, final OnProductAvailableListener
150149
.addQueryParameter("template", code.getTemplateName());
151150

152151
Shop shop = Snabble.getInstance().getCheckedInShop();
153-
if(shop != null) {
152+
if (shop != null) {
154153
builder.addQueryParameter("shopID", shop.getId());
155154
}
156155

@@ -270,24 +269,17 @@ private Product toProduct(ApiProduct apiProduct) {
270269
Unit encodingUnit = Unit.fromString(apiProduct.encodingUnit);
271270
builder.setEncodingUnit(encodingUnit);
272271

273-
if (apiProduct.weighByCustomer) {
274-
builder.setType(Product.Type.UserWeighed);
272+
273+
if (referenceUnit == null || referenceUnit == Unit.PIECE) {
274+
builder.setType(Product.Type.Article);
275275
} else {
276-
if (apiProduct.productType == ApiProductType.WEIGHABLE) {
277-
if (referenceUnit == null || referenceUnit == Unit.PIECE) {
278-
builder.setType(Product.Type.Article);
279-
} else {
280-
builder.setType(Product.Type.PreWeighed);
281-
}
282-
} else {
283-
builder.setType(Product.Type.Article);
284-
}
276+
builder.setType(Product.Type.PreWeighed);
285277
}
286278

287279
if (apiProduct.availability == null) {
288280
builder.setAvailability(Product.Availability.IN_STOCK);
289281
} else {
290-
switch(apiProduct.availability) {
282+
switch (apiProduct.availability) {
291283
case IN_STOCK:
292284
builder.setAvailability(Product.Availability.IN_STOCK);
293285
break;

core/src/main/java/io/snabble/sdk/codes/templates/CodeTemplate.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,13 @@ public List<Group> getGroups() {
243243
return Collections.unmodifiableList(groups);
244244
}
245245

246-
public <T extends Group> T getGroup(Class<? extends Group> clazz) {
246+
@SuppressWarnings("unchecked")
247+
public <T extends Group> T getGroup(Class<? extends T> clazz) {
247248
for (Group group : groups) {
248-
try {
249-
group.getClass().asSubclass(clazz);
249+
if (clazz.isInstance(group)) {
250250
return (T) group;
251-
} catch (ClassCastException ignored) {
252251
}
253252
}
254-
255253
return null;
256254
}
257255

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

Lines changed: 14 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
import java.util.ArrayList;
66
import java.util.List;
77

8-
import io.snabble.sdk.coupons.Coupon;
9-
import io.snabble.sdk.coupons.CouponCode;
108
import io.snabble.sdk.Product;
11-
import io.snabble.sdk.shoppingcart.ShoppingCart;
129
import io.snabble.sdk.Unit;
1310
import io.snabble.sdk.codes.ScannedCode;
1411
import io.snabble.sdk.codes.templates.CodeTemplate;
15-
import io.snabble.sdk.codes.templates.groups.EmbedGroup;
12+
import io.snabble.sdk.coupons.Coupon;
13+
import io.snabble.sdk.coupons.CouponCode;
14+
import io.snabble.sdk.shoppingcart.ShoppingCart;
1615
import io.snabble.sdk.shoppingcart.data.item.ItemType;
1716

1817
/**
@@ -24,16 +23,13 @@ public class ProductInfo {
2423
Product product;
2524
int quantity;
2625
ScannedCode scannedCode;
27-
boolean hasManualDiscount;
2826

2927
public ProductInfo(Product product,
3028
int quantity,
31-
ScannedCode scannedCode,
32-
boolean hasManualDiscount) {
29+
ScannedCode scannedCode) {
3330
this.product = product;
3431
this.quantity = quantity;
3532
this.scannedCode = scannedCode;
36-
this.hasManualDiscount = hasManualDiscount;
3733
}
3834
}
3935

@@ -42,7 +38,6 @@ public ProductInfo(Product product,
4238
private ArrayList<String> encodedCodes;
4339
private int codeCount;
4440
private boolean hasAgeRestrictedCode;
45-
private boolean hasAppliedManualDiscount;
4641

4742
public EncodedCodesGenerator(EncodedCodesOptions encodedCodesOptions) {
4843
encodedCodes = new ArrayList<>();
@@ -59,9 +54,9 @@ public void add(String code) {
5954
}
6055

6156
if (options.repeatCodes) {
62-
addScannableCode(code, false, false);
57+
addScannableCode(code, false);
6358
} else {
64-
addScannableCode("1" + options.countSeparator + code, false, false);
59+
addScannableCode("1" + options.countSeparator + code, false);
6560
}
6661
}
6762

@@ -94,10 +89,7 @@ public void add(ShoppingCart shoppingCart) {
9489
continue;
9590
}
9691

97-
productInfos.add(new ProductInfo(product,
98-
item.getUnitBasedQuantity(),
99-
item.getScannedCode(),
100-
item.isManualCouponApplied));
92+
productInfos.add(new ProductInfo(product, item.getUnitBasedQuantity(), item.getScannedCode()));
10193
}
10294
}
10395

@@ -147,14 +139,6 @@ public ArrayList<String> generate(String checkoutId) {
147139
}
148140
}
149141

150-
if (hasAppliedManualDiscount) {
151-
if (getCountSeparatorLength() > 0) {
152-
append("1" + options.countSeparator + options.manualDiscountFinalCode);
153-
} else {
154-
append(options.manualDiscountFinalCode);
155-
}
156-
}
157-
158142
finishCode();
159143

160144
ArrayList<String> ret = new ArrayList<>();
@@ -205,33 +189,7 @@ private void addProducts(final List<ProductInfo> productInfos, boolean ageRestri
205189
continue;
206190
}
207191

208-
if (productInfo.product.getType() == Product.Type.UserWeighed) {
209-
// encoding weight in ean
210-
Product.Code[] codes = productInfo.product.getScannableCodes();
211-
for (Product.Code code : codes) {
212-
if ("default".equals(code.template)) {
213-
continue;
214-
}
215-
216-
CodeTemplate codeTemplate = options.project.getCodeTemplate(code.template);
217-
if (codeTemplate != null && codeTemplate.getGroup(EmbedGroup.class) != null) {
218-
ScannedCode scannedCode = codeTemplate.code(code.lookupCode)
219-
.embed(productInfo.quantity)
220-
.buildCode();
221-
222-
if (options.repeatCodes) {
223-
addScannableCode(scannedCode.getCode(),
224-
ageRestricted,
225-
productInfo.hasManualDiscount);
226-
} else {
227-
addScannableCode("1" + options.countSeparator + scannedCode.getCode(),
228-
ageRestricted,
229-
productInfo.hasManualDiscount);
230-
}
231-
break;
232-
}
233-
}
234-
} else if (productInfo.product.getType() == Product.Type.PreWeighed) {
192+
if (productInfo.product.getType() == Product.Type.PreWeighed) {
235193
String transmissionCode = productInfo.product.getTransmissionCode(
236194
options.project,
237195
productInfo.scannedCode.getTemplateName(),
@@ -243,13 +201,9 @@ private void addProducts(final List<ProductInfo> productInfos, boolean ageRestri
243201
}
244202

245203
if (options.repeatCodes) {
246-
addScannableCode(transmissionCode,
247-
ageRestricted,
248-
productInfo.hasManualDiscount);
204+
addScannableCode(transmissionCode, ageRestricted);
249205
} else {
250-
addScannableCode("1" + options.countSeparator + productInfo.scannedCode.getCode(),
251-
ageRestricted,
252-
productInfo.hasManualDiscount);
206+
addScannableCode("1" + options.countSeparator + productInfo.scannedCode.getCode(), ageRestricted);
253207
}
254208
} else {
255209
int q = productInfo.quantity;
@@ -294,14 +248,10 @@ private void addProducts(final List<ProductInfo> productInfos, boolean ageRestri
294248

295249
if (options.repeatCodes) {
296250
for (int j = 0; j < q; j++) {
297-
addScannableCode(transmissionCode,
298-
ageRestricted,
299-
productInfo.hasManualDiscount);
251+
addScannableCode(transmissionCode, ageRestricted);
300252
}
301253
} else {
302-
addScannableCode(q + options.countSeparator + transmissionCode,
303-
ageRestricted,
304-
productInfo.hasManualDiscount);
254+
addScannableCode(q + options.countSeparator + transmissionCode, ageRestricted);
305255
}
306256
}
307257
}
@@ -314,7 +264,6 @@ private void finishCode() {
314264
encodedCodes.add(code);
315265
stringBuilder = new StringBuilder();
316266
codeCount = 0;
317-
hasAppliedManualDiscount = false;
318267
}
319268

320269
private int getCountSeparatorLength() {
@@ -325,7 +274,7 @@ private int getCountSeparatorLength() {
325274
}
326275
}
327276

328-
private void addScannableCode(String scannableCode, boolean isAgeRestricted, boolean hasManualDiscount) {
277+
private void addScannableCode(String scannableCode, boolean isAgeRestricted) {
329278
String nextCode = hasAgeRestrictedCode ? options.nextCodeWithCheck : options.nextCode;
330279

331280
if (isAgeRestricted
@@ -337,28 +286,18 @@ private void addScannableCode(String scannableCode, boolean isAgeRestricted, boo
337286
}
338287

339288
int charsLeft = options.maxChars - stringBuilder.length();
340-
int manualDiscountLength = hasManualDiscount ? options.manualDiscountFinalCode.length() : 0;
341-
int suffixCodeLength = Math.max(nextCode.length(), options.finalCode.length() + manualDiscountLength);
289+
int suffixCodeLength = Math.max(nextCode.length(), options.finalCode.length());
342290

343291
if (options.finalCode.length() > 0 && getCountSeparatorLength() > 0) {
344292
suffixCodeLength += getCountSeparatorLength() + 1;
345293
}
346294

347-
if (options.manualDiscountFinalCode.length() > 0 && getCountSeparatorLength() > 0) {
348-
suffixCodeLength += getCountSeparatorLength() + 1;
349-
}
350-
351295
int suffixCodes = 0;
352296

353297
if (options.finalCode.length() > 0) {
354298
suffixCodes++;
355299
}
356300

357-
if (manualDiscountLength > 0){
358-
suffixCodes++;
359-
hasAppliedManualDiscount = true;
360-
}
361-
362301
int codesNeeded = 1 + suffixCodes;
363302
int requiredLength = scannableCode.length()
364303
+ suffixCodeLength

0 commit comments

Comments
 (0)