55import java .util .ArrayList ;
66import java .util .List ;
77
8- import io .snabble .sdk .coupons .Coupon ;
9- import io .snabble .sdk .coupons .CouponCode ;
108import io .snabble .sdk .Product ;
11- import io .snabble .sdk .shoppingcart .ShoppingCart ;
129import io .snabble .sdk .Unit ;
1310import io .snabble .sdk .codes .ScannedCode ;
1411import 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 ;
1615import 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