Skip to content

Commit 93cba85

Browse files
committed
add support schema 1.19 and customer card prices
1 parent 80bff90 commit 93cba85

File tree

17 files changed

+90
-50
lines changed

17 files changed

+90
-50
lines changed
-82 KB
Binary file not shown.
88 KB
Binary file not shown.
113 KB
Binary file not shown.
88 KB
Binary file not shown.

core/src/androidTest/java/io/snabble/sdk/ProductDatabaseTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void testAllPromotionsQuery() {
4141

4242
@Test
4343
public void testTextSearchNoFTS() throws IOException, Snabble.SnabbleException {
44-
withDb("test_1_18.sqlite3", true);
44+
withDb("test_1_19.sqlite3", true);
4545

4646
ProductDatabase productDatabase = project.getProductDatabase();
4747
Cursor cursor = productDatabase.searchByFoldedName("gold", null);
@@ -150,25 +150,25 @@ public void testFindBySkuOnlineWithShopSpecificPrice() {
150150
ProductDatabase productDatabase = project.getProductDatabase();
151151
final Product product = findBySkuBlocking(productDatabase, "1");
152152
assertEquals(product.getSku(), "1");
153-
assertEquals(product.getPrice(), 399);
153+
assertEquals(product.getListPrice(), 399);
154154

155155
project.setCheckedInShop(project.getShops()[1]);
156156
final Product product2 = findBySkuBlocking(productDatabase, "1");
157157
assertEquals(product2.getSku(), "1");
158-
assertEquals(product2.getPrice(), 299);
158+
assertEquals(product2.getListPrice(), 299);
159159
}
160160

161161
@Test
162162
public void testFindBySkuWithShopSpecificPrice() {
163163
ProductDatabase productDatabase = project.getProductDatabase();
164164
final Product product = productDatabase.findBySku("salfter-classic");
165165
assertEquals(product.getSku(), "salfter-classic");
166-
assertEquals(product.getPrice(), 100);
166+
assertEquals(product.getListPrice(), 100);
167167

168168
project.setCheckedInShop(project.getShops()[1]);
169169
final Product product2 = productDatabase.findBySku("salfter-classic");
170170
assertEquals(product2.getSku(), "salfter-classic");
171-
assertEquals(product2.getPrice(), 200);
171+
assertEquals(product2.getListPrice(), 200);
172172
}
173173

174174
private Product findBySkuBlocking(ProductDatabase productDatabase, String sku) {
@@ -261,7 +261,7 @@ public void testApplyChangeSetInvalidDoesNotModifyDb() throws IOException {
261261
"DELETE FROM searchByName WHERE docid=3;";
262262

263263
Product product = productDatabase.findBySku("1");
264-
int p = product.getDiscountedPrice();
264+
int p = product.getListPrice();
265265

266266
boolean exceptionThrown = false;
267267
try {
@@ -273,17 +273,17 @@ public void testApplyChangeSetInvalidDoesNotModifyDb() throws IOException {
273273
assertTrue(exceptionThrown);
274274

275275
product = productDatabase.findBySku("1");
276-
assertEquals(p, product.getDiscountedPrice());
276+
assertEquals(p, product.getListPrice());
277277
}
278278

279279
@Test
280280
public void testFullUpdate() throws IOException {
281281
ProductDatabase productDatabase = project.getProductDatabase();
282-
productDatabase.applyFullUpdate(context.getAssets().open("update_1_18.sqlite3"));
282+
productDatabase.applyFullUpdate(context.getAssets().open("update_1_19.sqlite3"));
283283

284284
Product product = productDatabase.findBySku("0");
285285

286-
assertEquals(product.getPrice(), 349);
286+
assertEquals(product.getListPrice(), 349);
287287
assertEquals(product.getName(), "UPDATE");
288288

289289
product = productDatabase.findBySku("16");
@@ -293,7 +293,7 @@ public void testFullUpdate() throws IOException {
293293
@Test
294294
public void testFullUpdateDoesNotModifyOnCorruptedFile() throws IOException {
295295
ProductDatabase productDatabase = project.getProductDatabase();
296-
byte[] bytes = IOUtils.toByteArray(context.getAssets().open("update_1_18.sqlite3"));
296+
byte[] bytes = IOUtils.toByteArray(context.getAssets().open("update_1_19.sqlite3"));
297297
for (int i = 0; i < bytes.length; i++) {
298298
if (i % 4 == 0) {
299299
bytes[i] = 42;
@@ -312,12 +312,12 @@ public void testFullUpdateDoesNotModifyOnCorruptedFile() throws IOException {
312312
@Test
313313
public void testFullUpdateDoesNotModifyOnWrongMajorVersion() throws IOException {
314314
ProductDatabase productDatabase = project.getProductDatabase();
315-
InputStream is = context.getResources().getAssets().open("update_1_18.sqlite3");
316-
File outputFile = context.getDatabasePath("update_1_18.sqlite3");
315+
InputStream is = context.getResources().getAssets().open("update_1_19.sqlite3");
316+
File outputFile = context.getDatabasePath("update_1_19.sqlite3");
317317
FileOutputStream fos = new FileOutputStream(outputFile);
318318
IOUtils.copy(is, fos);
319319

320-
SQLiteDatabase db = context.openOrCreateDatabase("update_1_18.sqlite3", Context.MODE_PRIVATE, null);
320+
SQLiteDatabase db = context.openOrCreateDatabase("update_1_19.sqlite3", Context.MODE_PRIVATE, null);
321321
db.execSQL("UPDATE metadata SET value = 2 WHERE metadata.key = 'schemaVersionMajor'");
322322
db.close();
323323

@@ -374,10 +374,10 @@ public void testTransmissionCode() {
374374

375375
@Test
376376
public void testRecoverFromFileCorruptions() throws IOException, Snabble.SnabbleException, InterruptedException {
377-
withDb("test_1_18_corrupt.sqlite3");
377+
withDb("test_1_19_corrupt.sqlite3");
378378
Assert.assertNull(project.getProductDatabase().findBySku("1"));
379379

380-
prepareUpdateDb("test_1_18.sqlite3");
380+
prepareUpdateDb("test_1_19.sqlite3");
381381
final CountDownLatch countDownLatch = new CountDownLatch(1);
382382
project.getProductDatabase().update(new ProductDatabase.UpdateCallback() {
383383
@Override

core/src/androidTest/java/io/snabble/sdk/ShoppingCartTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ public void testNotEditable() {
103103
@Test
104104
public void testTotalPrice() {
105105
add(simpleProduct1);
106-
Assert.assertEquals(cart.get(0).getTotalPrice(), simpleProduct1.product.getDiscountedPrice());
106+
Assert.assertEquals(cart.get(0).getTotalPrice(), simpleProduct1.product.getListPrice());
107107

108108
cart.get(0).setQuantity(2);
109-
Assert.assertEquals(cart.get(0).getTotalPrice(), simpleProduct1.product.getDiscountedPrice() * 2);
109+
Assert.assertEquals(cart.get(0).getTotalPrice(), simpleProduct1.product.getListPrice() * 2);
110110

111111
add(preWeighedProduct);
112112
Assert.assertEquals(cart.get(0).getTotalPrice(), 47);
113113

114114
add(pieceProduct);
115-
Assert.assertEquals(cart.get(0).getTotalPrice(), pieceProduct.product.getDiscountedPrice() * 6);
115+
Assert.assertEquals(cart.get(0).getTotalPrice(), pieceProduct.product.getListPrice() * 6);
116116

117117
add(priceProduct);
118118
Assert.assertEquals(cart.get(0).getTotalPrice(), priceProduct.scannedCode.getEmbeddedData());

core/src/androidTest/java/io/snabble/sdk/SnabbleSdkTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public static void closeMockWebServer() throws IOException {
117117
@Before
118118
public void setupSdk() throws Snabble.SnabbleException, IOException {
119119
context = InstrumentationRegistry.getInstrumentation().getTargetContext();
120-
withDb("test_1_18.sqlite3");
120+
withDb("test_1_19.sqlite3");
121121
}
122122

123123
public void withDb(String testDbName) throws IOException, Snabble.SnabbleException {

core/src/androidTest/java/io/snabble/sdk/UnitTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.junit.Assert;
44
import org.junit.Test;
55

6-
import java.io.IOException;
76
import java.math.BigDecimal;
87
import java.math.RoundingMode;
98

@@ -15,15 +14,15 @@ public void testUnitPrices() {
1514
final Product test_g_1 = productDatabase.findBySku("test-g-1");
1615
final Product test_cm_1 = productDatabase.findBySku("test-cm-1");
1716

18-
Assert.assertEquals(139, test_ml_1.getPrice());
17+
Assert.assertEquals(139, test_ml_1.getListPrice());
1918
Assert.assertEquals(139, test_ml_1.getPriceForQuantity(1000, null, RoundingMode.HALF_UP));
2019
Assert.assertEquals(60, test_ml_1.getPriceForQuantity(431, null, RoundingMode.HALF_UP));
2120

22-
Assert.assertEquals(299, test_g_1.getPrice());
21+
Assert.assertEquals(299, test_g_1.getListPrice());
2322
Assert.assertEquals(299, test_g_1.getPriceForQuantity(1000, null, RoundingMode.HALF_UP));
2423
Assert.assertEquals(150, test_g_1.getPriceForQuantity(500, null, RoundingMode.HALF_UP));
2524

26-
Assert.assertEquals(199, test_cm_1.getPrice());
25+
Assert.assertEquals(199, test_cm_1.getListPrice());
2726
Assert.assertEquals(1990, test_cm_1.getPriceForQuantity(1000, null, RoundingMode.HALF_UP));
2827
Assert.assertEquals(498, test_cm_1.getPriceForQuantity(250, null, RoundingMode.HALF_UP));
2928
Assert.assertEquals(497, test_cm_1.getPriceForQuantity(250, null, RoundingMode.FLOOR));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ public String format(Product product, int price) {
8787
}
8888

8989
public String format(Product product, boolean discountedPrice, ScannedCode scannedCode) {
90-
int price = product.getPrice();
90+
int price = product.getListPrice();
9191

9292
if (discountedPrice) {
93-
price = product.getDiscountedPrice();
93+
price = product.getPrice(project.getCustomerCardId());
9494
}
9595

9696
if (scannedCode != null && scannedCode.hasPrice()) {

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

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public enum Type {
3636
PreWeighed(1),
3737

3838
/**
39-
* A product that needs to be user weighed. The price from {@link Product#getPrice()}
39+
* A product that needs to be user weighed. The price from {@link Product#getListPrice()}
4040
* is a base price of 1000g
4141
*/
4242
UserWeighed(2);
@@ -127,13 +127,15 @@ public String toString() {
127127
private Code[] scannableCodes;
128128
private int price;
129129
private int discountedPrice;
130+
private int customerCardPrice;
130131
private String imageUrl;
131132
private Product depositProduct;
132133
private Product[] bundleProducts;
133134
private Type type;
134135
private boolean isDeposit;
135136
private String subtitle;
136137
private String basePrice;
138+
private String scanMessage;
137139
private SaleRestriction saleRestriction = SaleRestriction.NONE;
138140
private Unit referenceUnit;
139141
private Unit encodingUnit;
@@ -163,7 +165,12 @@ public Code[] getScannableCodes() {
163165
return scannableCodes;
164166
}
165167

168+
@Deprecated // use getListPrice instead
166169
public int getPrice() {
170+
return getListPrice();
171+
}
172+
173+
public int getListPrice() {
167174
return price;
168175
}
169176

@@ -175,9 +182,19 @@ public String getSubtitle() {
175182
* Gets the discounted price, or the default price if this product has no discounted price,
176183
*/
177184
public int getDiscountedPrice() {
178-
return discountedPrice == 0 ? getPrice() : discountedPrice;
185+
return discountedPrice == 0 ? getListPrice() : discountedPrice;
179186
}
180187

188+
public int getPrice(String customerCard) {
189+
return customerCard != null ? getCustomerCardPrice() : getDiscountedPrice();
190+
}
191+
192+
public int getCustomerCardPrice() {
193+
return customerCardPrice == 0 ? getDiscountedPrice() : customerCardPrice;
194+
}
195+
196+
197+
@Deprecated // will be removed in a future version
181198
public boolean isDiscounted() {
182199
return discountedPrice > 0;
183200
}
@@ -277,7 +294,16 @@ public boolean getSaleStop() {
277294
return saleStop;
278295
}
279296

297+
/** Returns the identifier of the scan message to look up in i18n resources **/
298+
public String getScanMessage() {
299+
return scanMessage;
300+
}
301+
280302
public int getPriceForQuantity(int quantity, ScannedCode scannedCode, RoundingMode roundingMode) {
303+
return getPriceForQuantity(quantity, scannedCode, roundingMode, null);
304+
}
305+
306+
public int getPriceForQuantity(int quantity, ScannedCode scannedCode, RoundingMode roundingMode, String customerCardId) {
281307
if (type == Product.Type.UserWeighed || type == Product.Type.PreWeighed) {
282308
String lookupCode = scannedCode != null ? scannedCode.getLookupCode() : null;
283309

@@ -300,7 +326,7 @@ public int getPriceForQuantity(int quantity, ScannedCode scannedCode, RoundingMo
300326
encodingUnit = Unit.GRAM;
301327
}
302328

303-
int price = getDiscountedPrice();
329+
int price = getPrice(customerCardId);
304330
if (scannedCode != null && scannedCode.hasPrice()) {
305331
price = scannedCode.getPrice();
306332
}
@@ -312,7 +338,7 @@ public int getPriceForQuantity(int quantity, ScannedCode scannedCode, RoundingMo
312338
.setScale(0, roundingMode)
313339
.intValue();
314340
} else {
315-
return quantity * getDiscountedPrice();
341+
return quantity * getPrice(customerCardId);
316342
}
317343
}
318344

@@ -423,6 +449,11 @@ public Builder setDiscountedPrice(int discountedPrice) {
423449
return this;
424450
}
425451

452+
public Builder setCustomerCardPrice(int customerCardPrice) {
453+
product.customerCardPrice = customerCardPrice;
454+
return this;
455+
}
456+
426457
public Builder setImageUrl(String imageUrl) {
427458
product.imageUrl = imageUrl;
428459
return this;
@@ -468,6 +499,11 @@ public Builder setSaleStop(boolean saleStop) {
468499
return this;
469500
}
470501

502+
public Builder setScanMessage(String scanMessage) {
503+
product.scanMessage = scanMessage;
504+
return this;
505+
}
506+
471507
public Builder setReferenceUnit(Unit referenceUnit) {
472508
product.referenceUnit = referenceUnit;
473509
return this;

0 commit comments

Comments
 (0)