Skip to content

Commit 70db152

Browse files
committed
fixed regression in shopping cart when using multiple manual coupons
1 parent d444276 commit 70db152

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.68.2]
5+
6+
### Fixed
7+
- Fixed regression in shopping cart when using multiple manual coupons
8+
49
## [0.68.1]
510

611
### Fixed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ allprojects {
3333
}
3434

3535
project.ext {
36-
sdkVersion='0.68.1'
36+
sdkVersion='0.68.2'
3737
versionCode=1
3838

3939
compileSdkVersion=31

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import io.snabble.sdk.coupons.CouponType;
3232
import io.snabble.sdk.utils.Dispatch;
3333
import io.snabble.sdk.utils.GsonHolder;
34+
import io.snabble.sdk.utils.Logger;
3435

3536
/**
3637
* Class representing the snabble shopping cart
@@ -1366,7 +1367,9 @@ public BackendCart toBackendCart() {
13661367

13671368
if (cartItem.coupon != null) {
13681369
BackendCartItem couponItem = new BackendCartItem();
1369-
couponItem.id = cartItem.coupon.getId();
1370+
// this item id needs to be unique per item or else the
1371+
// promotion engine on the backend gets confused
1372+
couponItem.id = UUID.randomUUID().toString();
13701373
couponItem.refersTo = item.id;
13711374
couponItem.amount = 1;
13721375
couponItem.couponID = cartItem.coupon.getId();
@@ -1396,9 +1399,10 @@ public BackendCart toBackendCart() {
13961399
void resolveViolations(List<Violation> violations) {
13971400
for (Violation violation : violations) {
13981401
for (int i = data.items.size() - 1; i >= 0; i--) {
1399-
if (data.items.get(i).coupon != null && data.items.get(i).backendCouponId.equals(violation.getRefersTo())) {
1400-
Item item = data.items.get(i);
1402+
Item item = data.items.get(i);
1403+
if (item.coupon != null && item.backendCouponId != null && item.backendCouponId.equals(violation.getRefersTo())) {
14011404
data.items.remove(item);
1405+
data.modCount++;
14021406
boolean found = false;
14031407
for (ViolationNotification notification : data.violationNotifications) {
14041408
if (notification.getRefersTo().equals(violation.getRefersTo())) {
@@ -1418,6 +1422,7 @@ void resolveViolations(List<Violation> violations) {
14181422
}
14191423
}
14201424
notifyViolations();
1425+
updatePrices(false);
14211426
}
14221427

14231428
/**
@@ -1427,6 +1432,8 @@ void resolveViolations(List<Violation> violations) {
14271432
*/
14281433
public void removeViolationNotification(List<ViolationNotification> violations) {
14291434
data.violationNotifications.removeAll(violations);
1435+
data.modCount++;
1436+
notifyCartDataChanged(this);
14301437
}
14311438

14321439
@NonNull

0 commit comments

Comments
 (0)