Skip to content

Commit 4f5891c

Browse files
committed
prevent cart update loop
1 parent 10a0cbd commit 4f5891c

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
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.37.8]
5+
6+
### Fixed
7+
- Only update cart when it actually changed
8+
49
## [0.37.7]
510

611
### Added

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ allprojects {
3131
}
3232

3333
project.ext {
34-
sdkVersion='0.37.7'
34+
sdkVersion='0.37.8'
3535
versionCode=1
3636

3737
compileSdkVersion=30

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,10 @@ void insert(Item item, int index, boolean update) {
137137
}
138138
}
139139

140-
addCount++;
141-
modCount++;
142-
generateNewUUID();
140+
143141
items.add(index, item);
144142

145143
clearBackup();
146-
147144
checkLimits();
148145
notifyItemAdded(this, item);
149146

@@ -162,6 +159,9 @@ void insert(Item item, int index, boolean update) {
162159
});
163160

164161
if (update) {
162+
addCount++;
163+
modCount++;
164+
generateNewUUID();
165165
invalidateOnlinePrices();
166166
updatePrices(true);
167167
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ShoppingCartUpdater {
2727
private Handler handler;
2828
private CheckoutApi.PaymentMethodInfo[] lastAvailablePaymentMethods;
2929
private boolean isUpdated;
30+
private int successfulModCount = -1;
3031

3132
ShoppingCartUpdater(Project project, ShoppingCart shoppingCart) {
3233
this.project = project;
@@ -56,6 +57,10 @@ public void update() {
5657
}
5758

5859
final int modCount = cart.getModCount();
60+
if (modCount == successfulModCount) {
61+
return;
62+
}
63+
5964
Dispatch.mainThread(() -> checkoutApi.createCheckoutInfo(cart.toBackendCart(), null, new CheckoutApi.CheckoutInfoResult() {
6065
@Override
6166
public void success(final CheckoutApi.SignedCheckoutInfo signedCheckoutInfo, int onlinePrice, CheckoutApi.PaymentMethodInfo[] availablePaymentMethods) {
@@ -214,6 +219,8 @@ private void commitCartUpdate(int modCount, CheckoutApi.SignedCheckoutInfo signe
214219
cart.setOnlineTotalPrice(checkoutInfo.price.price);
215220
}
216221

222+
successfulModCount = modCount;
223+
217224
Logger.d("Successfully updated prices");
218225
} catch (Exception e) {
219226
Logger.e("Could not update price: %s", e.getMessage());

0 commit comments

Comments
 (0)